How to access data in a cell array
조회 수: 174 (최근 30일)
이전 댓글 표시
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.
채택된 답변
Sandro Lecci
2018년 5월 17일
Hy Auryn,
myCell{1}(2:60,1) should do the stuff.
Best, Sandro
댓글 수: 5
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
추가 답변 (2개)
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
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.
Alexandra Santos
2021년 3월 14일
I had a similar question but maybe commenting here may be better. Does anyone know how to append array data within within the cell array? I.e. If you were to access your matrix within the cell array and wanted to add a vector to it.
Thanks.
댓글 수: 2
Image Analyst
2021년 3월 14일
index = 5; % Whatever cell you want to deal with
ca{index} = [ca{index}, yourVector]; % For row vectors. Or use semicolon if they're column vectors.
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!