Selecting and Manipulating Specific Elements from Cell Array

조회 수: 1 (최근 30일)
Jonathan Pinko
Jonathan Pinko 2020년 7월 27일
댓글: Jonathan Pinko 2020년 7월 27일
A shortened version of my cell array:
{apples} {[1]}
{bananas} {[3]}
{apples} {[10]}
{apples} {[9]}
{bananas} {[7]}
I would like to write a code that creates a cell array that only consists of values from the second column that are on the same row as apples, i.e., this:
{[1]}
{[10]}
{[9]}
How would I do this?
Thanks,
Jonathan

채택된 답변

Jon
Jon 2020년 7월 27일
편집: Jon 2020년 7월 27일
% define original matrix
myCell = {'apples' 1;'bananas',3;'apples' 10;'apples',9;'bananas' 7}
% use logical indexing to just get rows that match your criteria
newCell = myCell(strcmp(myCell(:,1),'apples'),2)

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by