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

3 visualizzazioni (ultimi 30 giorni)
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 Commento
Aris John
Aris John il 13 Mag 2020
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.

Accedi per commentare.

Risposta accettata

Geoff Hayes
Geoff Hayes il 14 Mag 2020
Modificato: Geoff Hayes il 14 Mag 2020
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 Commento
Walter Roberson
Walter Roberson il 14 Mag 2020
[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.

Accedi per commentare.

Più risposte (1)

Aris John
Aris John il 26 Mag 2020
Thank you for the help.

Categorie

Scopri di più su Environment and Settings in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by