How to store multiple column vector generated from a for loop?
조회 수: 7 (최근 30일)
이전 댓글 표시
I have a function called func which returns A, B, C and D. This A, B, C, D each are 12 elements column vector. I am using this code
for delta = 0: 1: 40
[A,B,C,D] = func(delta);
end
Now after completing the for loop i will get 41 sets of A, B, C and D. How can i store them together?
I tried this
store = 0
for delta = 0: 1: 40
[A(store),B(store),C(store),D(store)] = func(delta);
end
But obviously there is an error like A(I) = X: X must have the same size as I. cause A is storing a 12 element column vector.
댓글 수: 0
채택된 답변
Stephen23
2018년 11월 12일
편집: Stephen23
2018년 11월 12일
N = 41;
A = nan(12,N);
B = nan(12,N);
C = nan(12,N);
D = nan(12,N);
for k = 1:N
[A(:,k),B(:,k),C(:,k),D(:,k)] = fun(k-1);
end
This will give four matrices with all of the output data.
참고 항목
카테고리
Help Center 및 File Exchange에서 Numeric Types에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!