Possible to iterate over table rows without a loop index variable?
29 ビュー (過去 30 日間)
古いコメントを表示
To iterate over the variables (columns) of a table, you can do this:
my_table = table([1; 2; 3], [4; 5; 6], ["Seven"; "Eight"; "Nine"])
for var = my_table
disp(var)
end
Is there a way to adjust this to operate on each row without using an index variable? Using a loop index variable, as follows, works fine but is a bit less elegant than the column-by-column solution.
for row_index = 1:height(my_table)
row = my_table(row_index, :);
disp(row)
end
2 件のコメント
採用された回答
Steven Lord
2024 年 4 月 18 日
To perform an operation on all rows of a table array you could use rowfun, but that isn't the same as writing a general for loop. I'd personally probably just use the for loop over 1:height(theTableArray).
2 件のコメント
Bruno Luong
2024 年 4 月 18 日
編集済み: Bruno Luong
2024 年 4 月 18 日
Some authority suggests using rowfun on table instead of for-loop row indexing if runtime performance matters.
Read the comments following my complain about combinations only providee table as output format.
Transpose the table as Torsen suggets or retreive the content of the table (without the tanle container) are two other work around of performance hi issue.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!