How to store data in matrix

조회 수: 3 (최근 30일)
N K
N K 2012년 2월 14일
Dear all.
I have problem to store data in to matrix with loop especially in ****** blank.
for loop = 1:1:Bl
disp (loop);
EX=B{loop};
[subRow,subCol]=size(EX);
for rowCount = 1:1:subRow
getDATA = dct2(EX(rowCount,:),[1,1]);
disp (getDATA);
********************
DD{loop}=[12,1];
DD{loop}[12,1]=getDATA;
***********************
end
end
I want to create DD matrix to store getDATA.
So,I try to generate 3D matrix but it only store last data (last data is store in all element).
Could you mind how to solve it?
Best.
ps.I hope you will understand what I want to do from code.

답변 (1개)

Benjamin Schwabe
Benjamin Schwabe 2012년 2월 14일
I dont' really get what you are trying there, but I'll try to give you an idea, what you could experiment with...
First thing, the last line of your code will not work at all: D{loop}(12,1)=getData will, depending on the values and size of getData.
1. Matlab is capable of setting up multidimensional matrices, like A(ind1,ind2,ind3). For more information, have a alook at the help, keyword: Multidimensial Arrays. This way you can avvoid using cell arrays.
2. This here is quite strange to me:
DD{loop}=[12,1];
DD{loop}[12,1]=getDATA;
Line 1 sets component loop of DD to a vector with two values 12 and 1.In the next step,you are overwriting this component of DD with a vector that should have 12 components and they should be equal to getDATA. If getDATA is just one number, all 12 values will be set to this.
In order to run the script properly, I still need to know what B is.

카테고리

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