フィルターのクリア

my loop dint work as i want

1 回表示 (過去 30 日間)
Amir Hamzah UTeM
Amir Hamzah UTeM 2012 年 7 月 9 日
here my code,
for j=1:3
for i=1:3
a(i)=randi(10)
end
x(j)=a(i);
end
this code is random 1-10 3 times eg: a=[1 3 9] let say
a(1)=[1 3 4]
a(2)=[3 4 6]
a(3)=[2 3 2]
i want to save x as something like this
x=[a(1) a(2) a(3)]
how to do that?can someone rectify my code? my code only work save the last data of a(i). i want to save 3 of them in x.
  1 件のコメント
Yash
Yash 2012 年 7 月 9 日
transpose this

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

採用された回答

Thomas
Thomas 2012 年 7 月 9 日
編集済み: Thomas 2012 年 7 月 9 日
for ii=1:3
for jj=1:3
a(ii,jj)=randi(10);
end
end
x=reshape(a',1,[])
or
x=randi(10,1,9)
  2 件のコメント
Amir Hamzah UTeM
Amir Hamzah UTeM 2012 年 7 月 9 日
thanks!
Thomas
Thomas 2012 年 7 月 9 日
編集済み: Thomas 2012 年 7 月 9 日
@ Luffy : it is a 3x3 matrix and a simple reshape can get it to the 1x9 vector..

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

その他の回答 (1 件)

Luffy
Luffy 2012 年 7 月 9 日
Simply,
for i = 1:9
a(i) = randi(10);
x(i) = a(i);
end
x

カテゴリ

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

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by