How does an m-file output appear in GUI axis?

I have an m-file that is executed by a pushbutton in a GUI. It extracts a number of jpeg images and averages them together. The final image is displayed in another figure window. How do I get the result to not appear in another figure window but an axis that is within the GUI interface?

回答 (3 件)

Jan
Jan 2011 年 7 月 4 日

1 投票

You can store the handle of the AXES object in the guidata. See "help guidata". Then you can use this handle for creating the new image.
Paulo Silva
Paulo Silva 2011 年 7 月 4 日

0 投票

In your GUI tag the axes you want to be used
set(gca,'Tag','SueGUIAxes')
Wherever you want to execute the code to show the results do this
axes(findall(0,'Tag','SueGUIAxes')) %set the axes as the current ones
%draw the image
Setting the axes to the current one might not work so it's better to give the handle for the axes to the function that plots/draws the image.
Example, if you want to plot on your GUI axes do this:
plot(findall(0,'Tag','SueGUIAxes'),1,1,'*')
Last step: In the GUIDE layout click on the background of the GUI with your mouse right button, choose GUI Options, now change the command line accessibility to ON, now my solution of tagging the axes works just fine.
It works while the GUI is open and the axes tagged so you can do that plot even in the command line or any m-file.

6 件のコメント

Sue
Sue 2011 年 7 月 4 日
Ok, I've tagged the axis but still very unsure how to do the next bit. I am really new to this and do not really understand, sorry.
The final bit of my m-file that outputs the result is as follows - do i need to modify this at all?
imwrite(uint8(T_mean),[filenameout,'.tif']) % NEGATIVE VALUES CAPPED AT ZERO
save(filenameout,'T_mean');
figure, imagesc(uint8(T_mean)), colormap gray
Thanks for your help
Paulo Silva
Paulo Silva 2011 年 7 月 4 日
seems that it's not possible to select the GUI axes for output, the solution is easy, put the m-file code inside your GUI
Sue
Sue 2011 年 7 月 5 日
Paulo, you say the answer is simple but I am very new to this so do apologise but do not understand how I can put the m-file inside the GUI.
I have attached my m-file to a pushbutton by putting the name of the m-file into the callback function of the uicontrols. My m-file now runs but when it finishes it returns the answer in a new figure window and not within the axes I have placed on the GUI interface. How can I tell the answer that i need it to appear in the axes and not a new figure window?
Many thanks, Sue
Paulo Silva
Paulo Silva 2011 年 7 月 5 日
Instead of using the name of the m-file you use the code of the m-file, it's just a simple copy and paste, copy the code to the same place where you call the m-file and your GUI now runs without requiring the m-file.
I also found why the solution I provided doesn't work properly, you must change a property of your GUI.
In the GUIDE layout click on the background of the GUI with your mouse right button, choose GUI Options, now change the command line accessibility to ON, now my solution of tagging the axes works just fine.
Sue
Sue 2011 年 7 月 5 日
I'm sorry I still do not understand. Where do I copy and paste the entire m-file? Up to now I am using Guide to create my GUI and have put the name of the m-file in the callback function of the pushbutton (i.e. when I double click the appropriate pushbutton in the GUI, I have placed the name of the m-file I wish it to run in the callback space). I don't think I can copy and paste an entire m-file into this space can I?
Also, I have just changed, using GUI options, the command line accessibility to On and now the image that I had originally placed in the axes before any results should end up there, has disappeared! And by changing the GUI options back again (or infact to any option) I cannot get my image to appear there again now. Its disappeared forever!! How do i get it back?
S x
Paulo Silva
Paulo Silva 2011 年 7 月 5 日
Calling the m-file by name or having the m-file code in your GUI is almost the same thing except in terms of memory zones and other small details. Remove the line where you call the m-file by it's name and paste the m-file code to the same line.
That's weird, how do you insert the image on the axes?

サインインしてコメントする。

Gerd
Gerd 2011 年 7 月 5 日

0 投票

Hi Sue, as Paulo stated it looks like you cannot select the axes with the imagesc command.
A workaround might be to use
im = imagesc(uint8(T_mean)), colormap gray
% get current figure handle
your_fig = gcf;
% copy the image to your axes in the GUI
copyobj(im,handles.youraxes)
%Close the im figure
close(your_fig);
Gerd

5 件のコメント

Sue
Sue 2011 年 7 月 5 日
Morning Gerd. Thanks for this but I am not quite sure what you are getting at? Do I put the above code in the m-file at the end? And what do I put instead of "your_fig"?
Sue x
Sue
Sue 2011 年 7 月 5 日
Woo, hold on - I've literally just placed your code above in place of the last line of mine - and it works!! The result shows in the axes. Fantastic. However, MATLAB also beebs at me and returns the following error message - what does this mean?
??? Undefined function or variable 'handles'.
Error in ==> CameraID_create_SF_blue at 78
copyobj(im,handles.result_axes)
??? Error while evaluating uicontrol Callback
Thanks, S x
Gerd
Gerd 2011 年 7 月 5 日
Hi Sue,
looks like the callback function doesn't know the handles structure. Please add the handles structure to the function call and to the function prototype of the CameraID_create_SF_blue
Sue
Sue 2011 年 7 月 5 日
Sorry but I have no idea what you mean?
S x
Sue
Sue 2011 年 7 月 18 日
Am still getting the above error message. You suggested adding the handles structure (which is result_axes - the 'tag' yes) to the function call? What is the 'function call'? And also to the function prototype of my m-file. What is a 'function prototype'?
Sorry for my lack of knowledge :-/
Sue x

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeGraphics Object Programming についてさらに検索

質問済み:

Sue
2011 年 7 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by