How to extract data from all matrixes of a cell array?

조회 수: 31 (최근 30일)
Yasyas9
Yasyas9 2020년 6월 30일
편집: Stephen23 2022년 9월 14일
I have a cell array 1x23 and every matrix contains 1x921600 and they're all same size but i only need to extract data from all the matrixes from array 1 until 456000 and again from 456000 until 764500. how can i do that ?

채택된 답변

Adam Danz
Adam Danz 2020년 6월 30일
편집: Adam Danz 2020년 6월 30일
For cell array "C"
newArray = cellfun(@(a){{a(1,1:456000);a(1,456000:764500)}},C);
newArray = [newArray{:}];
newArray is a 2xn cell array of row vectors where row 1, newArray(1,:), are the values 1:456000 and row 2, newArray(2,:), are values 456000:764500
newArray =
2×23 cell array
Columns 1 through 3
{1×456000 double} {1×456000 double} {1×456000 double} . . . . .
{1×308501 double} {1×308501 double} {1×308501 double} . . . . .
  댓글 수: 4
Yasyas9
Yasyas9 2020년 6월 30일
Thank you so much yes that's exactly what i wanted
Adam Danz
Adam Danz 2020년 6월 30일
Glad I could help.

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

추가 답변 (1개)

Reeshabh Kumar Ranjan
Reeshabh Kumar Ranjan 2020년 6월 30일
By extracting data, I assume you mean accessing the elements. This seems more of a syntax question.
Let's say you have a cell array
ca = {[1 2 3], [4 5 6], [7, 8, 9]}
Now, you can just loop over it
for i = 1 : length(ca)
matrix = ca{i}
% you have the matrix in each iteration now, access its elements any way you like
end
  댓글 수: 5
Evangelia Tripoliti
Evangelia Tripoliti 2022년 9월 14일
This is partly true. What if you have 100 matrices in a cell array? will you name the individually?
Stephen23
Stephen23 2022년 9월 14일
편집: Stephen23 2022년 9월 14일
"This is partly true."
Exactly which part is untrue?
"What if you have 100 matrices in a cell array?"
As stated in my previous comment, I would use simple and efficient indexing into the cell array. This is not just a hypothetical situation, I do this very often (e.g. processing TB of data in thousands of files).
"will you name the individually?"
No.

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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by