Attempt to reference field of non-structure array error message
3 次查看(过去 30 天)
显示 更早的评论
I am trying to plot histogram of n image through the below code. Images is 1xn cell
for i = 1:length(Images)
variable=Images{i}.img; %%error :Attempt to reference field of non-structure array
histogram(variable);
end
histogram(Images{2}.img); --this works
I know that the variable should be converted to string here as the file name abc.png (using a dot opertator)will be treated as class, but not sure what has to be done for that .
0 个评论
回答(2 个)
Image Analyst
2015-10-20
How did you stuff data into the Images cell array. I need to see that. Normally you don't add .anything after a cell reference. Extract the structure first, then get the field:
cellContents = Images{i}; % cellContents is a structure, I guess.
myImage = cellContents.img; % Take the "img" field of cellContents structure and make it into its own variable.
But I'm not really sure until I see how you made the Images cell array.
0 个评论
Walter Roberson
2015-10-20
Your Images{i} is a struct array. When you access the .img field you are asking for the .img field of all of the array entries; that requires multiple outputs but you only have one output.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!