acessing cell arrays with different number of rows

조회 수: 3 (최근 30일)
Damith
Damith 2014년 9월 3일
댓글: Star Strider 2014년 9월 3일
Hi,
I have cell array "out" 1x123 cells. Within each cell of out{1,1}, <1x3 cells. How can I access 2 and 3 columns of each cell within "out" and store in flows2 matrix. I am having a difficulty because each cell of "out" has different number of rows.
So, I tried this way
for j=1:length(csvFiles)
formatOut = 'yyyy';
flows2(:,j)=[str2num(datestr(datenum([out{1,j}{1,2}],1900),formatOut)) [out{1,j}{1,3}]];
end
I am receiving this error. Subscripted assignment dimension mismatch.
My question is, any other efficient way of doing this?
Any suggestion is appreciated.
Thanks in advance,

채택된 답변

Star Strider
Star Strider 2014년 9월 3일
The only option I can see is to create flows2 as a cell array:
flows2{j} = ...
  댓글 수: 6
Damith
Damith 2014년 9월 3일
Thanks. How can I store q2 values in different columns for all the cells. Something like this,
for i=1:length(csvFiles)
q2(:,i)=flows2{i}(:,2)
end
When I tried this I received this error: Subscripted assignment dimension mismatch.
I know know this is due to uneven number of rows of 2nd column of each cells. Is there a way to store with different names like q1,q2,....length(csvFiles)?
Star Strider
Star Strider 2014년 9월 3일
For the same reason as with flows2 (different size columns), you will need to store them in a cell array:
for i=1:length(csvFiles)
q2{i}=flows2{i}(:,2)
end
If you wanted to, you could do that in your ‘j’ loop. Simply add it as a separate line and save an extra loop.

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

추가 답변 (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