Exrapolate values from cell matrix and operations with cell elements

조회 수: 4 (최근 30일)
Hi all
i have a cell matrix where each cell is nx3 double. Assuming you have the coordinates ( [y k] where y and k are arrays )of the cells that interest me, I want, from these selected cells, to extrapolate only the first of the three columns.
How can be done?
Thank you for the help
Regards

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 10월 14일
편집: Ameer Hamza 2020년 10월 14일
I am not sure about the point related to extrapolation. If you just want to extract the first column of selected cells, then you can try this
C; % cell matrix
y; % row index of selected cells
k; % column index of selected cells
idx = sub2idx(size(C), y, k);
C_selected = C(idx);
first_columns = cellfun(@(x) {x(:,1)}, C_selected);
if all columns have same length then you can create a matrix
first_columns = [first_columns{:}];
  댓글 수: 4
EldaEbrithil
EldaEbrithil 2020년 10월 15일
Thanks you very much Ameer!!
I have also another question: consider two array A and B with the same number of cell. Each cell has different length, i want to perform operations with the elements content inside each cell so which of the following expressions is better?
C{i}=A{i}/{B{i}
C{i}=A{i}./{B{i}
C{:,i}=A{:,i}./{B{:,i}
Ameer Hamza
Ameer Hamza 2020년 10월 15일
It depends on what you are trying to do. / is used for "matrix division", whereas ./ is used for element-wise division. If corresponding cells of A and B have an equal number of elements, then I think you want to use
C{i}=A{i}./{B{i}

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

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