Reference to non-existent field 'image'. Error in Untitled2 (line 10) a80 = double(x1_image.image); -----Need help

조회 수: 2 (최근 30일)
A =imread('0001BG.tiff')
save('80s', 'A')
[x_file, x_folder] = uigetfile('*.mat', 'Select 80s-file');
x1_image = load([x_folder,x_file]);
cd(x_folder);
a80 = zeros(1024);
a80 = double(x1_image.image);
  댓글 수: 1
Aris John
Aris John 2020년 5월 13일
I want to convert a .tiff file to a .mat file 80s, then load it into an empty array a80. The a80 initially created by zeros(1024). While executing the last line it shows an error as follows.
Error in Untitled2 (line 10)
a80 = double(x1_image.image);
I am new to matlab, please help.

댓글을 달려면 로그인하십시오.

채택된 답변

Geoff Hayes
Geoff Hayes 2020년 5월 14일
편집: Geoff Hayes 2020년 5월 14일
Aris - what make you think that image is a valid field for x1_image? In your example, you save the A variable to the 80s.mat file and so when you load this file as
x1_image = load([x_folder,x_file]);
then the field for x1_image will be A. Your code would then be
A =imread('0001BG.tiff')
save('80s', 'A')
[x_file, x_folder] = uigetfile('*.mat', 'Select 80s-file');
x1_image = load([x_folder,x_file]);
cd(x_folder);
a80 = zeros(1024);
a80 = double(x1_image.A);
The above code is only valid if A is the variable that is always saved to the 80s.mat files. You could use fieldnames to get the list of fields of x1_image and your code might become
A =imread('0001BG.tiff')
save('80s', 'A')
[x_file, x_folder] = uigetfile('*.mat', 'Select 80s-file');
x1_image = load([x_folder,x_file]);
structFieldnames = fieldnames(x1_image);
if ~isempty(structFieldnames)
cd(x_folder);
a80 = zeros(1024);
a80 = double(getfield(x1_image, structFieldnames{1}));
end
Here I'm assuming that the first fieldname corresponds to the image of interest...
  댓글 수: 1
Walter Roberson
Walter Roberson 2020년 5월 14일
[x_file, x_folder] = uigetfile('*.mat', 'Select 80s-file');
if ~ischar(x_file); return; end %user cancel
x1_image = load( fullfile(x_folder, x_file) );
uigetfile does not promise that the returned folder will end in a path separator character, and it does not promise to be consistent about that either. A couple of weeks ago, someone on a Windows system was having trouble and it turned out that uigetfile was not putting in the path seperator. Using fullfile() makes it unecessary to think about whether the separator is there are not.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Aris John
Aris John 2020년 5월 26일
Thank you for the help.

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by