How to make a reference to multiple subelements of a cell without for loop (to create a plot)

조회 수: 3 (최근 30일)
lets say I have a axb cell , each cell contains a 1xn double I want to make a plot like this plot({1,:}(1,end)) , i.e. for the first row of this cell I want to plot each cells last datapoint. I know this syntax doesn't work for cells, and it gives me the error "Incorrect cell or structure reference involving "end". Most likely cause is a reference to multiple elements of a cell or structure followed by additional subscript or structure references."
But how would you do this seemingly simple task?

채택된 답변

José-Luis
José-Luis 2012년 11월 6일
your_vals = cellfun(@(x) x(end),your_cell)

추가 답변 (1개)

Harshit
Harshit 2012년 11월 6일
Hi Felix, You have to use cell2mat. It converts your code to matrix. You have knowledge about n so pick up every nth element. It can be done easily.
  댓글 수: 1
Felix
Felix 2012년 11월 6일
편집: Felix 2012년 11월 6일
Unfortunately the size of n is different in every cell, thats why I wanted to use "end". Therefore cell2mat gives an error because the whole cell does not form a rectangle.

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

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by