필터 지우기
필터 지우기

How to dynamically change the table input and variables names?

조회 수: 2 (최근 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
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!

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by