how can I write all for loop outputs in single matrix?

how can I write all for loop results in single matrix?
For example
ans =
-2 -2 -1
-2 -2 1
-2 2 -1
-2 2 1
2 -2 -1
2 -2 1
2 2 -1
2 2 1
ans =
0 0 -3
0 0 3
I want to get a result such as
ans =
-2 -2 -1
-2 -2 1
-2 2 -1
-2 2 1
2 -2 -1
2 -2 1
2 2 -1
2 2 1
0 0 -3
0 0 3

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 5월 19일
편집: Azzi Abdelmalek 2013년 5월 19일
For vertical concatenation
A=[1 2 3;4 5 6;7 8 9]
B=[10 20 30;40 50 60]
out=[A;B]

댓글 수: 5

ok, but here all my outputs equal to just one parameter... for example what if for loop give two result such as
A=[1 2 3;4 5 6;7 8 9] A=[10 20 30;40 50 60]
maybe it is very basic but sorry I am very new
When you write
A=[1 2 3;4 5 6;7 8 9]
A=[10 20 30;40 50 60]
The first A will be erased by the second A, If you want to avoid this:
A=[1 2 3;4 5 6;7 8 9];
B=A;
A=[10 20 30;40 50 60];
out=[B;A]
sory I think I couldnot explain properly... For example I have a for loop
for i=1:size(a)
% a&b two matrices and their dimensions are different
s = bsxfun(@times,a,b);
v=unique(s,'rows')
end
therefore, my outputs equal to same parameter "v"
What is the problem with your previous comment?
Lottie Wardman
Lottie Wardman 2021년 10월 6일
편집: Lottie Wardman 2021년 10월 6일
Hi,
Thought I would jump in as I'm having the same difficultly. The loop produces say 21 results, all labelled 'A'. Vertical concatination would work, but as all outputs are produced at once, it's not possible (or practical) to label each output with an alternative letter.
TIA

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

Andrei Bobrov
Andrei Bobrov 2013년 5월 20일
Try this construct
out = [];
for jj = ...
% here your execution
A = ...
out = [out;A];
end

댓글 수: 1

Hi,
Sorry I'm very new to MATLAB, please could you explain a little more? I can't seem to use the above to 'join' all the loop results in a single matrix.
TIA

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

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2013년 5월 19일

편집:

2021년 10월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by