How to dynamically change the table input and variables names?

21 ビュー (過去 30 日間)
Chandra Sekhar Kommineni
Chandra Sekhar Kommineni 2022 年 2 月 8 日
編集済み: Sourav Karmakar 2022 年 2 月 14 日
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

回答 (1 件)

Sourav Karmakar
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
Tnew = table(); %your table specifications here for N=4
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!


Find more on Loops and Conditional Statements in Help Center and File Exchange




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by