How to plot in GUI from obtained values?
1 次查看(过去 30 天)
显示 更早的评论
Hello,
I have a problem that I have been trying to solve but I run out of ideas.
The programm is as followed: I input two data, which gives the directory to xls files. Those files are read, and the values they contain as well. Those values undergo several calculation to give an output vector. My goal is to plot this output vector. If I do it by hand: no problem. But what I tried to create is a GUI interface to make more user friendly. The computation does not have any problem. I have a button that launches is. It works.
But then I have another button to plot the result but I cannot get it to work. The axis are present, but Matlab does not understand which value I want to plot. My first idea was to read the data from the file created contaning the output vector. Given that it s a file created by matlab, it is quiet tricky to extract the values - it does not recognise any extension I put on it. So I decided to keep the output values as a vector inside matlab. But I don't know how to link the vector that is present in the function for the computation push button to the plot function button.
I tried the following way:
(TF_CMB and TF_B are the data I am trying to plot versus the frequence)
In the computation function:
handles.TF_CMB=TF_CMB;
handles.TF_B=TF_B;
handles.output=hObject;
guidata(hObject, handles);
And then in the plot function
TF_CMB = get(handles.button_start);
TF_B = get(handles.button_start);
freq=[250,315,400,500,630,800,1000,1200,1600,2000,2500,3150,4000,5000,6300,8000,10000];
plot(handles.axes1_2D,freq,TF_CMB,'r')
hold on
plot(handles.axes1_2D,freq,TF_B)
hold off
This is error that comes from it:
_??? Error using ==> plot
Conversion to double from struct is not possible.
Error in ==> cmb>pushbutton5_Callback at 183
plot(handles.axes1_2D,freq,TF_CMB,'r')
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> cmb at 20
gui_mainfcn(gui_State, varargin{:});
Error in ==>
@(hObject,eventdata)cmb('pushbutton5_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback_
Any ideas ?
0 个评论
回答(3 个)
Johannes Korsawe
2013-10-31
Use the handles structure and the built-in function guidata:
function xls_read_button_Callback(hObject, eventdata, handles)
...
(some XLS read)
...
handles.TF_CMB=TF_CMB;
guidata(hObject,handles); % This is the important line
function data_plot_button_Callback(hObject, eventdata, handles)
TF_CMB=handles.TF_CMB; % The vector data of TF_CMB is available inside this function now
plot(TF_CMB);
Finished.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!