MATLAB Answers

How to access data in a cell array

971 ビュー (過去 30 日間)
Auryn_
Auryn_ 2018 年 5 月 17 日
コメント済み: Image Analyst 2018 年 5 月 17 日
Hi,
I have a cell array of 1x10 where each of the 10 arrays are matrices of 80x31. If I want to access the data of each of the cells but just (2:60,1), how can I access it?
I tried with mycell{1,[2:60,1]} but it doesn't work.
Any help will be very much appreciated.

  0 件のコメント

サインイン to comment.

採用された回答

Sandro Lecci
Sandro Lecci 2018 年 5 月 17 日
Hy Auryn,
myCell{1}(2:60,1) should do the stuff.
Best, Sandro

  5 件のコメント

表示 2 件の古いコメント
Sandro Lecci
Sandro Lecci 2018 年 5 月 17 日
Try accessing the cell like this:
myCell{1,1}(2:60,1); %and
myCell{1,2}(2:60,1);
Sandro
edit: Are you sure that your cell don't have the same values in the portion you are interested in?
Auryn_
Auryn_ 2018 年 5 月 17 日
Hi Sandro,
it works :)
Now, how can I plot it in a 3D plot? I have tried
surf=[1:60-1,1:10,mycell{:}(2:60,1)];
hold on
but it doesn't work :(
Sandro Lecci
Sandro Lecci 2018 年 5 月 17 日
I suggest you have a look at the documentation of the surf function, type doc surf in the command window to see how to use this function.
You need to provide the X, Y and Z coordinates of the surface you want to plot --> surf(X,Y,Z).
Considering your case I would extract all the lines of interest (from 2 to 60, column one, from all cells) and create a new matrix that contains them, then plot the matrix using the surf function using the correct syntaxis.
We are now off topic with respect to the main question (which was solved).
Good luck, Sandro

サインイン to comment.

その他の回答 (1 件)

Image Analyst
Image Analyst 2018 年 5 月 17 日
Try this. Say you're in a loop over k
for k = 1 : length(mycell)
% Extract the k'th cell's contents.
thisCellContents = mycell{k}; % Will be a 80x31 array.
subArray = thisCellContents(2:60, 1); % Extract columns 2-60 of column 1
% Now do something with subarray.....
end

  2 件のコメント

Auryn_
Auryn_ 2018 年 5 月 17 日
Hi,
thanks for the reply.
I try to plot it now in a 3D plot but I do not know how to do it:
I have tried
surf=[1:60-1,k,mycell{:}(2:60,1)];
hold on
Image Analyst
Image Analyst 2018 年 5 月 17 日
surf() is a function. You don't assign anything TO it. That will blow away the surf() function. Bad idea. You CALL the surf() function by passing your data INTO it. See the help.

サインイン to comment.

サインイン してこの質問に回答します。


Translated by