replacing a for loop

1 次查看(过去 30 天)
Mnr
Mnr 2015-11-28
评论: Mnr 2015-11-29
Hello all,
I have a simple piece of code that I would like to get rid of the for loop. I would appreciate your help.
for n=1:K
idx=row((((n-1)*dc)+1):(n*dc));
end
where as an example K=4, dc=2, and row=[1;3;2;3;1;4;2;4];

采纳的回答

Walter Roberson
Walter Roberson 2015-11-28
t = reshape(row, dc, []);
idx = t(:,1:K);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by