Reputation: 63
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 :)
Upvotes: 0
Views: 92
Reputation: 2149
output{1,:}
is a comma-separated list; it contains the 1024 matrices of the first row of output
, so length
has 1024 arguments. The best way to obtain the number of columns is using size(...,2)
:
for i = 1:size(output,2)
figure
imagesc(output{1,i});
colormap('jet')
colorbar;
end
As for the second error, there is something wrong with dinfo.name
; probably, it is also a comma-separated list because dinfo
is a structure array. Try using dinfo(i).name
instead of dinfo.name(i)
.
Upvotes: 1