[SOLVED] Save image in cell array ARRAY{i,y} and access them with image(ARRAY{i,y})?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
John Kau
am 5 Jul. 2015
Bearbeitet: John Kau
am 5 Jul. 2015
Hi there!
My system:
Windows 8.1 and MATLAB2015a
My issue: When I save a JPG image in a structure array, in this case stiAll{i,y}
fileName = strcat('group_',strGr,'_',strVal,'.jpg');
fileNameStr = char(fileName);
stiAll{i,y} = imread(fileNameStr);
and I try to retrieve the saved image with image(stiAll(i,y)) I get the following error message from MATLAB:
Invalid datatype for Image CData. Numeric or logical matrix required for image CData.
If I save the image without the {i,y} suffix, so that the image is saved in a normal variable, not in a structure array, I can retrieve the image. However, for my programme I would need to save images in the respective cells of a structure array or something similar.
Any idea how to get this done successfully?
Thanks J
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (1)
Image Analyst
am 5 Jul. 2015
If you're using braces, you're saying that the variable is a cell array. See http://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F
A structure is not a cell and a structure array is not a cell array. So don't use braces.
baseFileName = sprintf('group_%s_%s.jpg', strGr, strVal);
fullFileName = fullfile(pwd, baseFileName);
if exist(fullFileName, 'file)
% File exists. Add to structure.
stiAll(i,y) = imread(fullFileName);
else
% File does not exist
message = sprintf('File does not exist:\n%s', fullFileName);
uiwait(warndlg(message));
end
Siehe auch
Kategorien
Mehr zu Structures finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!