Filter löschen
Filter löschen

GUI Project Help?

2 Ansichten (letzte 30 Tage)
Cristina Muniz
Cristina Muniz am 18 Feb. 2022
Kommentiert: Image Analyst am 18 Feb. 2022
In my GUI I want to display an image depending on the selection my user makes.
This is my current code for that section of the GUI:
panelSelection = get(handles.pnlND, 'SelectedObject');
disease = get(panelSelection,'String')
A = imread('Alzheimers_EEG.png');
B = imread('Dementia_EEG.png');
C = imread('BrainCancer_EEG.png');
D = imread('Epilepsy_EEG.jpg');
E = imread('Depression_EEG.png');
F = imread('Squizophrenia_EEG.png');
G = imread('BorderlinePersonalityDisorder_EEG.jpg');
H = imread('Parkinsons_EEG.jpg');
I = imread('Stroke_EEG.png');
J = imread('TIA_EEG.png');
K = imread('Normal_EEG.png');
if strcmp (disease, A)
imshow(A)
else
if strcmp (disease, B)
imshow(B)
else
if strcmp (disease, C)
imshow(C)
else
if strcmp (disease, D)
imshow(D)
else
if strcmp (disease, E)
imshow(E)
else
if strcmp (disease, F)
imshow(F)
else
if strcmp (disease, G)
imshow(G)
else
if strcmp (disease, H)
imshow(H)
else
if strcmp (disease, I)
imshow(I)
else
if strcmp (disease, J)
imshow(J)
else
if strcmp (disease, K)
imshow(K)
else
end
end
end
end
end
end
end
end
end
end
end
The problem is, I don't know how to tell the program that if the user selects - for example - 'Stroke' in the GUI panel displayed then that equals I and I = the corresponding image - in this case I = imread('Stroke_EEG.png'). How can I specify this?

Antworten (1)

DGM
DGM am 18 Feb. 2022
Bearbeitet: DGM am 18 Feb. 2022
I would approach it something like this. I don't know how your figure is set up, but somewhere you should have a list of the strings you're putting in the menu/list object. Here, I'm going to presume that this is how it's defined.
Somewhere in figure setup or parameter definitions, you'd have lists associating the menu text and the corresponding filenames ...
% these are ostensibly the list of options that are in the menu
imagenamestrings = {'Alzheimers', ...
'Dementia', ...
'Brain Cancer', ...
'Epilepsy', ...
'Depression', ...
'Schizophrenia',...
'BPD', ...
'Parkinsons', ...
'Stroke', ...
'TIA', ...
'Normal'};
% this is the corresponding list of the actual filenames
imagefilenames = {'Alzheimers_EEG.png', ...
'Dementia_EEG.png', ...
'BrainCancer_EEG.png', ...
'Epilepsy_EEG.jpg', ...
'Depression_EEG.png', ...
'Squizophrenia_EEG.png', ...
'BorderlinePersonalityDisorder_EEG.jpg', ...
'Parkinsons_EEG.jpg', ...
'Stroke_EEG.png', ...
'TIA_EEG.png', ...
'Normal_EEG.png'};
Then somewhere in some callback function ...
% get the string from the object
panelSelection = get(handles.pnlND, 'SelectedObject');
disease = get(panelSelection,'String')
% look up the filename based on the menu string
thisfilename = imagefilenames{strcmpi(disease,imagenamestrings)}
% read just that one file and do something with it
A = imread(thisfilename);
imshow(A)
As Benjamin mentioned, it may be necessary to construct the full path to feed imread(). If you have a fixed path to the directory containing the image files, you can construct the full path like so:
% say that this is defined somewhere with other parameters
imagedirpath = 'path/to/images'; % something like that
% ...
% then somewhere in whatever callback does the loading
A = imread(fullfile(imagedirpath,thisfilename));
PS don't worry about the moderator bot flagging you. Considering the ubiquity of single-use spam accounts, it's critical of new users. I took care of it as soon as I saw it was you.
  3 Kommentare
DGM
DGM am 18 Feb. 2022
Apparently the values in disease aren't matching anything in the list imagenamestrings. If the menu/listbox options are being defined by imagenamestrings, then I'm not sure what the issue would be. If the menu/listbox options are being defined explicitly by something else, then that discrepancy would be a cause.
Ultimately, I can't know for sure unless I see how the figure is being set up and have a means to troubleshoot it.
Image Analyst
Image Analyst am 18 Feb. 2022
@Cristina Muniz plase attach your .fig file and .m file so we can debug this.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by