Adding new column of data from loop

57 ビュー (過去 30 日間)
jacob Mitch
jacob Mitch 2019 年 10 月 31 日
編集済み: KALYAN ACHARJYA 2019 年 10 月 31 日
Say I have a loop running how would I create a new variable that holds the columns I want say.
for ....
v= %some code that ouputs a 1 row 10 column data set say [1;2;3;4;5;...10]
x=v % x adds v as the first column.
% Then adds v again on the second loop run as the 2nd column then adds v again for the 3rd column
end
%so something like x=v, x=vv, x=vvv it keeps adding a new column to x of the data produced by v
I hope you can help. Thank you.
  1 件のコメント
KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 10 月 31 日
編集済み: KALYAN ACHARJYA 2019 年 10 月 31 日
Here 1 row 10 column data set say [1;2;3;4;5;...10];, Example is is 10 rows,1 column?
Which are you looking for?

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

採用された回答

meghannmarie
meghannmarie 2019 年 10 月 31 日
x = nan(10,num_loops);
for n = 1:num_loops
v = %some code that ouputs a 1 row 10 column data set say [1;2;3;4;5;...10]
x(:,n) = v; % x adds v as the first column.
end

その他の回答 (1 件)

the cyclist
the cyclist 2019 年 10 月 31 日
編集済み: the cyclist 2019 年 10 月 31 日
x = zeros(10,3);
for i = 1:3
v = rand(10,1);
x(:,i) = v;
end

カテゴリ

Help Center および File ExchangeCell Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by