Amend a column vector to a matrix array
이전 댓글 표시
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
Christopher Arreola
2021년 12월 8일
Matt J
2021년 12월 8일
That will work, but it will run very slowly, due to
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
2021년 12월 8일
답변 (1개)
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)
카테고리
도움말 센터 및 File Exchange에서 Fluid Dynamics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!