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