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 CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by