1

I am making a GUI in which there is a multi-line edit box.

the user will have to input the 3 x-y coordinates in this edit box at a time:

[345.567 123.123] 
[390.567 178.098]
[378.000 125.987]

by clicking the push button I want these coordinates to be "saved" in the Matlab GUI workspace in the form of a matrix and by clicking another push button "reloaded" from the workspace so that they can be available for future use.

How can I do that?

Can anyone guide me with this? Help would be appreciated!

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Rabs
  • 11
  • 1
  • 2

2 Answers2

1

There are a number of ways to manage data in GUIDE-generated GUIs. The easiest IMO is to use guidata.

For example inside the "Save" push button callback, you would access the edit box string contents, parse as matrix of numbers as save it inside the handles structure.

function pushbuttonSave_Callback(hObject, eventdata, handles)
    handles.M = str2num(get(handles.edit1, 'String'));
    guidata(hObject, handles);
end

Next in the "load" button, we do the opposite, by loading the matrix from the handles structure, converting it to string, and set the edit box content:

function pushbuttonLoad_Callback(hObject, eventdata, handles)
    s = num2str(handles.M, '%.3f %.3f\n');
    set(handles.edit1, 'String',s)
end

screenshot

If you want to export/import the data to/from the "workspace", you can use the ASSIGNIN/EVALIN function:

assignin('base','M',handles.M);

and

handles.M = evalin('base','M');
Amro
  • 123,847
  • 25
  • 243
  • 454
  • thanks Amro for your kind help but what i did is: `function savepoint_Callback(hObject, eventdata, handles) user_entry = getappdata(handles.edit1 , 'yourVariable'); v = get(handles.edit1,'String'); matrix= str2num(v); assignin('base','a',matrix);` this variable 'a' is stored in the workspace in the form of the matrix like: a = 0.3170 0.1272 0.2849 0.2467 0.3419 0.3609 but i am not able to perform more operations on 'a'. how can i further use a???? how can i do w1= a(1,2)+a(2,2) ??? please help me! – Rabs Aug 02 '12 at 05:41
0

to save data:

setappdata(h,'name',value) 

to load data:

value = getappdata(h,'name')
values = getappdata(h)

where h is the handle you store the data in, name is the variable of the data, value is the actual data.

Keegan Keplinger
  • 627
  • 5
  • 15
  • Xurtio! my variable 'a' is stored in the workspace. but i am not able to perform further operations on that variable.how can i do that w1= a(1,2)+a(2,2)??? – Rabs Aug 02 '12 at 06:03
  • That sounds more like a problem of scope, but it seems like you're asking a different question now? If so, you should star a new thread and focus on your original question here. – Keegan Keplinger Aug 02 '12 at 06:23