How to save 2 images from function and use it in another function in MATLAB GUI?
1 view (last 30 days)
Show older comments
Hi! I have made a matlab gui which has a pop up menu and one button.I want the user to select an image set from pop up menu and then the images to be displayed in two different axes and saved in two variables respectively,so i can use them in push button function. I have managed to display the images in axes but i have problem with saving the images in variables.I have tried some things but they didnt work. This is my code so far:
contents = get(hObject,'Value');
switch contents
case 1
Myimage1=imread('image1.jpg');
imshow(Myimage1, 'Parent',handles.axes1);
Myimage2=imread('image2.jpg');
imshow(Myimage2 , 'Parent',handles.axes2);
case 2
Myimage1=imread('image3.jpg');
imshow(Myimage1 , 'Parent',handles.axes1);
Myimage2=imread('image4.jpg');
imshow(Myimage2, 'Parent',handles.axes2);
otherwise
end
Thank you in advance.
1 Comment
Image Analyst
on 20 Apr 2015
The images in the variables are already saved. If they weren't you wouldn't be able to use imread() on them.
Answers (1)
Geoff Hayes
on 23 Apr 2015
Perna - you will want to save the data to the handles structure in one of your callbacks so that you can access it in another callback. To save the updated handles structure you will need to use guidata. For example, in one callback you would do
handles.Myimage1=imread('image1.jpg');
guidata(hObject,handles);
and then you would access this image from the other callback as
handles.Myimage1
Try doing the above and see what happens!
0 Comments
See Also
Categories
Find more on Display Image in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!