How to add columns to form a matrix?

2 ビュー (過去 30 日間)
Ahmad Hasnain
Ahmad Hasnain 2018 年 12 月 12 日
回答済み: madhan ravi 2018 年 12 月 12 日
I am calculating a column vector in a FOR loop. I get N columns and I want to put them in a matrix.
for i = 1: N
dc(i) = ...
end
dcmatrix =[ dc(1) ; dc(2); .... ;dc(N) ]
%% The above example of dcmatrix is doing it manually. How can I do it with a code?%%
I calculate this dc column vector. I want to all the column vector in the form of matrix. I don't know how to do it.

採用された回答

Adam Danz
Adam Danz 2018 年 12 月 12 日
編集済み: Adam Danz 2018 年 12 月 12 日
Create the matrix (or vector) from within the for-loop, not afterwards.
dcmatrix = nan(N, 1); %allocate the matrix (I don't know how many rows you need).
for i = 1:N
dcmatrix(i) = ... %On each loop, data is stored in row i
end
  1 件のコメント
Ahmad Hasnain
Ahmad Hasnain 2018 年 12 月 12 日
Thanks...

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

その他の回答 (2 件)

madhan ravi
madhan ravi 2018 年 12 月 12 日
dcMatrix = dc.'

madhan ravi
madhan ravi 2018 年 12 月 12 日
dc(i,1) % - > column vector
dc(1,i) % - > row vector
  1 件のコメント
Ahmad Hasnain
Ahmad Hasnain 2018 年 12 月 12 日
Your previous answer also worked. Thanks...

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

カテゴリ

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

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by