필터 지우기
필터 지우기

Amend a column vector to a matrix array

조회 수: 3 (최근 30일)
Christopher Arreola
Christopher Arreola 2021년 12월 8일
댓글: Christopher Arreola 2021년 12월 8일
What are some simple ways to amend a column vector to an array? I am trying to avoid setting a fixed number of column vectors to an array and would rather amend column vector after column vector with a while loop until it reaches the end of the loop. Feel it would be unnecessary to fix the length of the array if this could happen and it would be more fluid
  댓글 수: 4
Voss
Voss 2021년 12월 8일
That will work. This also works:
w(:,end+1) = z;
It is a good idea to pre-allocate if possible, however, like Matt J points out in his answer.
Christopher Arreola
Christopher Arreola 2021년 12월 8일
hugh, well i'll take the increase in round off error if it provides a better matrix that fits my data set more accurately

댓글을 달려면 로그인하십시오.

답변 (1개)

Matt J
Matt J 2021년 12월 8일
편집: Matt J 2021년 12월 8일
it would be unnecessary to fix the length of the array if this could happen and it would be more fluid
No, it won't be more fluid, because of
A compromise would be to hold the columns in a cell array and then combine them at the end, e.g.,
i=1;
c={};
while i<10
c{i}=rand(4,1);
i=i+1;
end
A=cell2mat(c)
A = 4×9
0.4293 0.5831 0.1375 0.3251 0.9970 0.2210 0.0956 0.4595 0.1706 0.9880 0.2839 0.6171 0.5244 0.4020 0.7433 0.8065 0.7895 0.0911 0.7028 0.6208 0.9873 0.0436 0.8547 0.3176 0.0456 0.8947 0.7712 0.5441 0.3587 0.6043 0.4594 0.0559 0.9560 0.8444 0.7481 0.7811

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by