Logical Indexing of Cell Array containing matrices
1 回表示 (過去 30 日間)
古いコメントを表示
Georg Söllinger
2016 年 11 月 7 日
コメント済み: Walter Roberson
2016 年 11 月 8 日
Hi everyone,
I need help with indexing cell arrays. I have a cell array, which contains matrices in the first, a string in the second and three identifiers in the third-fifth columns (see attached screenshot)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/157753/image.png)
. What I want to do is a plot of specific values, which are located in the matrix of the first column and want to access those values with logical indexing of the identifiers. As a matter of fact, my logical indexing fails, it is not as straight forward as for standard arrays.
See my code below:
plot(R1{(R1{:,3} == phi && R1{:,4} == layer && R1{:,5} == speed),1}(:,6), ...
R1{(R1{:,3} == phi && R1{:,4} == layer && R1{:,5} == speed),1}(:,3),'Color',color(1,:),'LineStyle','-','LineWidth',1)
I have already tried the solutions with strcmp, but this doesn't work either...
Thanks for your help in advance! Georg
3 件のコメント
採用された回答
Walter Roberson
2016 年 11 月 7 日
mask = cell2mat(R1(:,3)) == phi & cell2mat(R1(:,4) == layer & cell2mat(R1(:,5)) == speed);
subset = R1(mask,:);
plot(subset{1, 1}(:,6), subset{1, 1}(:,3), 'Color', color(1,:), 'LineStyle', '-', 'LineWidth', 1);
hold on
arrayfun(@(ROWIDX) plot(subset{ROWIDX, 1}(:,6), subset{ROWIDX, 1}(:,3), 'Color', color(1,:), 'LineStyle', '-', 'LineWidth', 1), 2:size(subset,1));
If you already have "hold on" in effect then you can use
mask = cell2mat(R1(:,3)) == phi & cell2mat(R1(:,4) == layer & cell2mat(R1(:,5)) == speed);
subset = R1(mask,:);
arrayfun(@(ROWIDX) plot(subset{ROWIDX, 1}(:,6), subset{ROWIDX, 1}(:,3), 'Color', color(1,:), 'LineStyle', '-', 'LineWidth', 1), 1:size(subset,1));
2 件のコメント
Walter Roberson
2016 年 11 月 8 日
arrayfun is there to plot all the subsets. Each subset member is one row in which the condition was true.
I do not assume that only one line matches the criteria.
その他の回答 (1 件)
KSSV
2016 年 11 月 7 日
abs is not defined for cell. Convert it to a array/ matrix and then use abs.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Data Type Conversion についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!