call a variable in a timetable from a cell matrix

조회 수: 1 (최근 30일)
Xymbu
Xymbu 2022년 1월 14일
댓글: Xymbu 2022년 1월 14일
I have a loop with the column/variable names of a timetable need to be called in a loop
for 1 = 1:10
a(:,i) = Timetable.VariableNamesMatrix{i}
end
I bolded the part im having an issue with. How can I call a string from a cell array and use it in this fashion so that for example
VariableNamesMatrix{1} = Var1
and the code would enact the part in the loop as Tiimetable.Var1 when i = 1;

채택된 답변

Walter Roberson
Walter Roberson 2022년 1월 14일
편집: Walter Roberson 2022년 1월 14일
for 1 = 1:10
a(:,i) = Timetable.(VariableNamesMatrix{i});
end
But you should consider just using
a = table2array(Timetable, VariableNamesMatrix);
  댓글 수: 1
Xymbu
Xymbu 2022년 1월 14일
Thanks! for both answers def solved this issue. I will use the table2array(). I appreciate the quick response!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by