How to callback and save a plot, as image in guide?

조회 수: 4 (최근 30일)
Yudi
Yudi 2018년 10월 19일
댓글: Image Analyst 2018년 10월 20일
I have created a GUI with radio buttons which plots two graphs at a time in the interface. There is also a write results push button which when pushed stores data in excel sheet, along with this I also want to save the plots in the .jpeg format to the same folder. Since this has to be done once the button is pushed , I want a similar command like setappdata to set the plot with some specific name and later in the push button function I can getappdata and store using Imwrite. Please suggest a function to store the plot and then call back in another function.
Attached is the image of GUI

답변 (2개)

Image Analyst
Image Analyst 2018년 10월 19일

Yudi
Yudi 2018년 10월 20일

Thank you for your immediate feedback. My real problem is not with exporting plot to png, its how to callback in another function.

As stated I am using multiple radio buttons to plot on same axes one by one code is as follows:

function radiobutton4_Callback(hObject, eventdata, handles)
time=getappdata(0,'time');
P3I=getappdata(0,'p3i');
P3V_G=getappdata(0,'p3v_g');
P3V_dev=getappdata(0,'p3v_dev');
axes(handles.axes8);
plot (time, P3I,'b', time, P3V_G,'g'); 
legend ('Inca', 'Vehicle');
title ('Back Pressure'); xlabel('Time (s)'); ylabel('P3 (mbar)');
image1=getframe(handles.axes8); % Here I wanted to set the plot to a frame
setappdata(hObject,'image1',image1); % Here I wanted to set it for callback. 
axes(handles.perdev);
plot (time, P3V_dev,'r')
title ('Back Pressure Deviation'); xlabel('Time (s)'); ylabel('P3 Deviation (%)');

Now that I have set the graphic I want to save it after pressing push button code is as follows:

function res_Callback(hObject, eventdata, handles)
res=getappdata(0,'res');
set(handles.result,'string','Storing Result . . .');
pause(1);
path=getappdata(0,'path');
image1=getappdata(hObject,'image1'); % Here I want to extract the image
imgpath=fullfile(path,'Figure1.jpg');
export_fig(image1,imgpath); % Here I am storing the image to file path, but its return error that argument is empty
file=fullfile(path,'Mass Correlation Result.xlsx');
xlswrite(file, res);
set(handles.result,'string','Results Saved');

It is not a complex problem but I am new to matalab, your help will be much appreciated.

  댓글 수: 1
Image Analyst
Image Analyst 2018년 10월 20일
It could be that your using "path" as the name of your variable is causing problems. path is a built-in reserved variable that you should never overwrite/destroy. Call it "folder" and try again.
I also don't see any need for pause(1).
Also, you can use the more convenient OOP method of setting properties instead of using the old fashioned get() and set():
handles.result.String = 'Results Saved';

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by