Question

I have a GUI in MATLAB (created using GUIDE) which has a pushbutton callback and 2 edit boxes. The edit boxes are to be filled first after which pressing the pushbutton plots a figure on a pair of axes.

Upon Pressing this pushbutton, I execute a .m file which sends the data in the edit boxes data serially to a micro-controller and receives some calculated data on the basis of the sent data. This data is produced in another a seperate function file which handles the serial data sent back from the microcontroller.

Now, I want to transfer this data to the pushbutton callback function, so that it can be plotted on a pair of axes. How do I do this without global variables? The problem is complicated by the fact that I have to continuosly update the plot everytime I receive serial data from the microcontroller.

The outline for the pushbutton callback is as below:

% --- Executes on button press in angle_speed_pushbutton_callback.
function angle_speed_pushbutton_callback_Callback(hObject, eventdata, handles)
% hObject    handle to angle_speed_pushbutton_callback (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


angle1 = handles.xy_angle;  %These values are obtained from the edit boxes
angle2 = handles.xz_angle; 
delay = handles.speed;

Testbed_Calibration_main; %Main function which sends data serially to the microcontroller

% I want to transfer the data received by the function which handles the microcontroller output here

% plot transferred data on axes here 

Thank you in advance. :-)

Was it helpful?

Solution

I think what you want is to use guidata, there's a very good explanation here and a post here on the same topic. You could also use, setappdata, but that's similar to global data.

OTHER TIPS

I had a similar problem while doing a GUI for a program. I finally realised that the gui m-file can be a script, thus making the all the object handles available. From what I understand, maybe you could apply this to your problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top