Repeating a task for each row without loop
古いコメントを表示
I'd like to do this expression without a loop,
x = [1, 1; 2, 2; 3, 3; 4, 7; 8, 8; 9, 9; 10, 15; 16, 16; 17, 17];
for i = 1:size(x,1)
y(i,1) = {[x(i,1):x(i,2)]}
end
Thanks in advance,
4 件のコメント
Bob Thompson
2018 年 3 月 27 日
So, you just want to set each row of y to be a cell containing the corresponding row of x? How are you using y later in your code? Do you need to even specify y as a separate variable, or can you just index x later on?
Jonathan Pelletier-Marcotte
2018 年 3 月 27 日
Bob Thompson
2018 年 3 月 27 日
Ok. I personally don't know of a way to conduct a specific operation for each row of a matrix without defining a loop to run through the rows. It might be possible with some fancy indexing, but I don't know how.
Jonathan Pelletier-Marcotte
2018 年 3 月 27 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!