フィルターのクリア

Generating Plots From Cell Array

2 ビュー (過去 30 日間)
itend
itend 2017 年 8 月 25 日
コメント済み: Star Strider 2017 年 8 月 25 日
Hello,
I have a cell array (3 x 4), called output, containing a 1024 x 1024 matrix in each cell. I want to plot the 4 matrices in ouput{1,:}. Furthermore, I have a structure, called dinfo, which correspondingly contains the names of each matrix (field with matrix names = "name"). I want each image to be titled with its name. Here is the code I have written thus far:
for i = 1:length(output{1,:})
figure
imagesc(output{1,i});
colormap('jet')
colorbar;
title(num2str(dinfo.name(i)))
end
I keep getting the error that "length has too many input arguments". If I change the code to avoid the length function-related error:
for i = 1:4
figure
imagesc(output{1,i});
colormap('jet')
colorbar;
title(num2str(dinfo.name(i)))
end
I get the error, "Expected one output from a curly brace or dot indexing expression, but there were 4 results".
Any thoughts on how I could resolve both of these errors?
Thank you for your time :)

採用された回答

Star Strider
Star Strider 2017 年 8 月 25 日
This works for me (in R2017a):
dinfo.name = [1,2,3,4]; % Create Structure
output = {rand(5), rand(5), rand(5), rand(5)}; % Create Cell Array
for i = 1:length(output)
figure
imagesc(output{1,i});
colormap('jet')
colorbar;
title(num2str(dinfo.name(i)))
end
  2 件のコメント
itend
itend 2017 年 8 月 25 日
編集済み: itend 2017 年 8 月 25 日
Hello,
Thank you for your response. The issue with the length function has been resolved. However, calling the field from the structure array is still problematic.
The structure has 6 fields, each field has 4 entries. I am interested in labeling each output image produced in the code with its corresponding title from the "name" field in the structure. In other words, images 1 -> 4 get labeled with names 1 -> 4 obtained from the "name" field in the structure, respectively. I am still getting the same error, any suggestions?
Star Strider
Star Strider 2017 年 8 月 25 日
I’m lost.
You initially wrote ‘I have a cell array (3 x 4), called output’, so I created a cell array to (successfully) test my code. Now it seems you’re addressing a structure, and structure referencing is different. I don’t have your structure array, so I can’t write code specifically to reference it in your loop. Please see the documentation on Access Data in a Structure Array (link) for details.

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by