Filter löschen
Filter löschen

How to dynamically change the table input and variables names?

2 Ansichten (letzte 30 Tage)
Chandra Sekhar Kommineni
Chandra Sekhar Kommineni am 8 Feb. 2022
Bearbeitet: Sourav Karmakar am 14 Feb. 2022
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

Antworten (1)

Sourav Karmakar
Sourav Karmakar am 14 Feb. 2022
Bearbeitet: Sourav Karmakar am 14 Feb. 2022
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!

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by