save all columns into a new variable in a loop

1 回表示 (過去 30 日間)
fadams18
fadams18 2020 年 4 月 15 日
コメント済み: Stephen23 2020 年 4 月 15 日
I have the following setup. Every time k changes i get new values of T.
T is of size 1x1000, so i want to end the end have a 3x1000 matrix.
for k =1:3
T = myfunc( X, r)
end

採用された回答

Stephen23
Stephen23 2020 年 4 月 15 日
Use indexing:
T = nan(3,1000); % preallocate!
for k = 1:3
T(k,:) = myfunc(X,r);
end
  2 件のコメント
fadams18
fadams18 2020 年 4 月 15 日
Funny thing i just did it. haha thanks though. I was doing T(:,k) and i just switched it and it worked. I really need to master indexing of matrices/vectors
Stephen23
Stephen23 2020 年 4 月 15 日
"I really need to master indexing of matrices/vectors"
Yes. Efficient indexing of arrays, matrices, and vectors is really one of MATLAB's key strengths.

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

その他の回答 (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