Combine output from for loop into one long vecor, then put that row into a cell.

1 回表示 (過去 30 日間)
Ellie
Ellie 2015 年 8 月 20 日
コメント済み: Star Strider 2015 年 8 月 20 日
Hi all,
I have this code, and it works how I would like for the first row, but I am having trouble generalizing it.
y = randi(10,10);
out = [];
m = sparse(y);
for j1 = 1:N
y1 = (j1-1) * ones(1, m(1,j1));
out = [out y1];
end
Thanks in advance.

採用された回答

Star Strider
Star Strider 2015 年 8 月 20 日
Not certain I understand what you want, but if you want ‘out’ to be a cell array, just address it that way:
out{j1} = [out y1];
  12 件のコメント
Ellie
Ellie 2015 年 8 月 20 日
Fantastic! Thank you so much!!
Star Strider
Star Strider 2015 年 8 月 20 日
My pleasure!
I’m very happy we got this sorted!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by