필터 지우기
필터 지우기

[SOLVED] Save image in cell array ARRAY{i,y} and access them with image(ARRAY{i,y})?

조회 수: 2 (최근 30일)
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

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2015년 7월 5일
image(stiAll{1,1})

추가 답변 (1개)

Image Analyst
Image Analyst 2015년 7월 5일
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

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by