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)
  1 件のコメント
Jonathan Pinko
Jonathan Pinko 2020 年 7 月 27 日
This works perfectly, thank you.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by