Assigning cell to variable only assigns first value

I have a function designed to return a string by comparing an input string against a predetermined array defining pairs of values. The problem is on the very last line which doesn't seem to like setting the final cell array of strings. grouping is a scalar string, and groupsCats and catsBehavs are both 2xN cell arrays of string pairs.
function behaviours = getBehaviours(obj, grouping)
[~, catIndices] = find(strcmp(grouping, obj.groupsCats));
catName = obj.groupsCats{2, catIndices};
[~, behaviourIndices] = find(strcmp(catName, obj.catsBehavs));
behaviourIndices = rot90(behaviourIndices); % Rotate to return correct strings in next step
behaviours = obj.catsBehavs{1, behaviourIndices};
end
During debugging running obj.catsBehavs{1, behaviourIndices} will return the correct list, but assigning it to a variable will only set the first value on the array. I'm pretty sure I'm missing some basic cell syntax here but I can't work it out.

 採用された回答

Adam
Adam 2016 年 5 月 6 日

1 投票

Use parentheses instead:
behaviours = obj.catsBehavs(1, behaviourIndices);
You want to keep the cell array type so don't use { } to extract what is in it instead

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCharacters and Strings についてさらに検索

製品

質問済み:

2016 年 5 月 6 日

回答済み:

2016 年 5 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by