conatinate matrix which is getting updated in loop

hi,
for s=1:500
consall1(s,:,:)=[cons1, cons2, cons31, cons32, cons33, cons34];
end
from above mentioned for loop.I need a single matrix with 6 rows.please reply with your ideas.
sita

댓글 수: 4

Adam
Adam 2015년 3월 17일
Why are you putting the same result into 500 different layers of your consall1 result? There are quicker ways to achieve that than in a loop if it is what you really wish to do.
What do you mean by a single matrix with 6 rows? A 2d matrix? We have no idea what cons1, cons2, etc are in your example. Are they scalars? matrices?
Stephen23
Stephen23 2015년 3월 17일
편집: Stephen23 2015년 3월 17일
@sita: Your statements and the code given contradict each other:
for s = 1:500
consall1(s,:,:) = ...
end
will create an array with 500 rows. But you also state that "I need a single matrix with 6 rows". So which do you want: 500 or 6 rows?
Also the allocation
consall1(s,:,:) = [cons1, cons2, cons31, cons32, cons33, cons34];
will fit the given values into one row of consall1 based on the indexing used, regardless of their orientation in a vector, so reshaping the vector will not change the shape of the output array.
You need to explain the problem better, with an example of the desired output.
sita
sita 2015년 3월 18일
my cons1....cons34 changes in loop so after every iteration i have different consall1..i want to combine them with 500 rows 6 coloms..soryy for not explaining clearly
So besides the needless introduction of a third dimension, what is wrong with your code fragment? I assume that you cannot vectorize the calculation of cons1,...34. To speed up a bit (though it won't make a big difference here), you can preallocate consall1 with
consall1=zeros(500,6);
and then start overwriting the zeros with the values in the loop.

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

답변 (0개)

카테고리

도움말 센터File Exchange에서 Valentines Day에 대해 자세히 알아보기

제품

태그

질문:

2015년 3월 17일

댓글:

2015년 3월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by