필터 지우기
필터 지우기

Creation of vectors in for loop and save those and fill vector up with new column vectors

조회 수: 1 (최근 30일)
Hello!
Is there a way, lets say, if I have a for loop where for every iteration it creates two column vectors, A=[1 1 1] and B=[2 2 2]
If i now want to save those two in every iteration , let say, V=[A B]
When I come in to next iteration I want to save those from the first iteration so it fills up, so iteration two I create A’ and B’ so I want the following result,
V=[A B A’ B’], where A, B, A’, B’ are column vector. So for this example I get for example,
V=[ 1 1 1; 2 2 2; 1’ 1’ 1’; 2’ 2’ 2’];

채택된 답변

John Chilleri
John Chilleri 2017년 4월 24일
Hello,
This can indeed be done:
V = [];
for ...
A = [...];
B = [...];
V = [V A B];
end
Hope this helps!
  댓글 수: 2
John Chilleri
John Chilleri 2017년 4월 24일
If you want to be memory efficient, you can do:
n = number of iterations;
V = zeros(1,n*6);
for i = 1:n
A = [...];
B = [...];
V(6*i-5:6*i) = [A B];
end
Good luck!
Daniel Arvidsson
Daniel Arvidsson 2017년 4월 24일
Thanks John! You just saved my day, been pretty black upon now, thanks again!! =)
Best regards,
Daniel

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

추가 답변 (0개)

카테고리

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