How to dynamically change the table input and variables names?
1 次查看(过去 30 天)
显示 更早的评论
I'm trying to create a table in loop, accoding to loop inputs my L_vec and t_vec is 3 and sometimes 4. But I'm not able to do it implicitly.
for N=4
Tnew = table(T,N,kk,L_vec(1),L_vec(2),L_vec(3),L_vec(4),t_vec(1),t_vec(2),t_vec(3),t_vec(4),Rt,RL,...
'VariableNames' , { 'T','N','tr' ,'Sigma' ,'Meff', 'L0','L1','L2','L3', 't0','t1','t2','t3', 'Rt', 'RL'});
for N=3
Tnew2 = table(T,N,kkk,L_vec(1),L_vec(2),L_vec(3),t_vec(1),t_vec(2),t_vec(3),Rt,RL,...
'VariableNames' , { 'T','N','tr' ,'Sigma' ,'Meff', 'L0','L1','L2', 't0','t1','t2', 'Rt', 'RL'});
Can you someone please tell me how to concate two different column of size and changing the variables names in single loop? Thank you so much in advance
0 个评论
回答(1 个)
Sourav Karmakar
2022-2-14
编辑:Sourav Karmakar
2022-2-14
Hey Chandra Sekhar ,
As per my understanding, you want to create the table and change variable names in a single loop as per your loop input size. So, you can use if-else condition to check your input vectors size and create the table accordingly.
For example,
for i=1:10 %let's say for 10 iterations
if( N==3 ) % your_condition_here
Tnew = table(); %your table specifications here for N=3
else
Tnew = table(); %your table specifications here for N=4
end
end
Also, you can change the variables names by setting the 'Tnew.Properties.VariableNames' value.
You can also refer to the following documentation for more reference:
Hope this helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!