Indexing in complex cell arrays
이전 댓글 표시
I have a 3275x1 cell array that looks like the following (see attatched images). I'm trying to extract only the values on the first column when deep into the cell. For instance, I tried the following code that didn't work:
x = a{:,1}{:,1}{1,1}
This is me trying to isolate only the values in the first column of the part of the cell you can see in image a{1,1}{1,1}. In the code above, I tried to tell matlab that I want all rows, but just for that single column, to be isolated.
To clarify, in image a{1,1}{1,1}, the value in the first column is an x-value, the value in the second column is a y-value, and the value in the third column is a t-value. I'm trying to put all the x-values into one cell array, all the y-values in another cell array, and all the t-values in another cell array.
To give more examples:
a{1,1}{1,1}{1,1} would be an x-value.
a{1,1}{1,1}{1,2} would be a y-value
a{1,1}{1,1}{1,3} would be a t-value
a{1,1}{2,1}{1,1} would be an x-value
a{1,1}{2,1}{1,2} would be a y-value
a{1,1}{2,1}{1,3} would be a t-value
(etc).
I'm fairly new to matlab, so i'd be greatly appreciative of anyone who could point me in the direction of some resources to help me learn how to analyse this data (or, of course, any code which can perform the task I want.).
Thanks so much!
채택된 답변
추가 답변 (1개)
KSSV
2023년 2월 1일
% Make dummy data for demo
a = cell(10,1) ;
for i = 1:10
m = randsample(5:10,1) ;
b = cell(m,1) ;
for j = 1:m
b{j} = {rand(1,3)} ;
end
a{i} = b ;
end
% convert
iwant = vertcat(a{:}) ;
iwant = cell2mat(vertcat(iwant{:})) ;
x = iwant(:,1) ;
y = iwant(:,2) ;
t = iwant(:,3) ;
카테고리
도움말 센터 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!