Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Problem loading data back into fields

Subject: Problem loading data back into fields

From: Matt

Date: 7 Dec, 2012 11:54:08

Message: 1 of 5

Hello !

I have used this function with success in the past, but it seems that it doesn't work for my new project. Basically I am saving "edit text" boxes content to a .mat file, which seem to work fine, but when I try to load that file and put the values back into the "edit text" boxes, I get this error :

----------------
Error using handle.handle/set
Invalid or deleted object.

set(handles.var1_edittext, 'string', state.var1_edittext);
----------------

I would like to put back the value "var1" into the "var1_edittext" box, but it doesn't work. To save it to my .mat file I've used the following function :

----------------
state.var1_edittext = get(handles.var1_edittext, 'string');
----------------

I am confused because I have used the same technic for previous projects and it worked !

Thanks a lot in advance ! :-)

Subject: Problem loading data back into fields

From: Kristin

Date: 7 Dec, 2012 13:31:08

Message: 2 of 5

"Matt" wrote in message <k9sld0$icf$1@newscl01ah.mathworks.com>...
> Hello !
>
> I have used this function with success in the past, but it seems that it doesn't work for my new project. Basically I am saving "edit text" boxes content to a .mat file, which seem to work fine, but when I try to load that file and put the values back into the "edit text" boxes, I get this error :
>
> ----------------
> Error using handle.handle/set
> Invalid or deleted object.
>
> set(handles.var1_edittext, 'string', state.var1_edittext);
> ----------------
>
> I would like to put back the value "var1" into the "var1_edittext" box, but it doesn't work. To save it to my .mat file I've used the following function :
>
> ----------------
> state.var1_edittext = get(handles.var1_edittext, 'string');
> ----------------
>
> I am confused because I have used the same technic for previous projects and it worked !
>
> Thanks a lot in advance ! :-)

I think handles.var1_edittext might not exist anymore, or your GUI gets deleted in the process? What is the purpose of this reloading of "values" (strings) back into the edit boxes, because there might be a better way to do it?

Subject: Problem loading data back into fields

From: Matt

Date: 7 Dec, 2012 17:02:08

Message: 3 of 5

Thank you for your answer !

In fact the edit text box does not get deleted. For example if during the saving process I'm using the same set command to put a random value into that edit text box, it works. But when I want to put the value that I have saved from that box, it says the box doesn't exist anymore, while I can still see it !

I am using this function to save what was written in the edit text box, and then after opening again the program, I want to load the save file so the value goes back into the box.

Thanks !

Subject: Problem loading data back into fields

From: Matt

Date: 8 Dec, 2012 15:15:09

Message: 4 of 5

So I am giving a bit more details. If I am using the same method as the tutorial below, it works :

http://blogs.mathworks.com/videos/2008/10/31/video-saving-the-state-of-a-gui/

The thing is that I'm allowing the user to choose a name for the file. Here is my code :

------------------------------------
function savedata_box_Callback(hObject, eventdata, handles)
    savename = uiputfile(...
    {'*.mat','MATLAB data file (*.mat)';}, ...
    'Save the file as...');
    assignin('base', 'savename', savename);
    state.val1 = get(handles.val1_box, 'string');
    save (savename)

function loaddata_box_Callback(hObject, eventdata, handles)
    loadname = uigetfile( ...
    {'*.mat','MATLAB data file (*.mat)';}, ...
    'Select a data file...');
    load (loadname)
    set(handles.val1_box, 'string', state.val1);
------------------------------------

Again it has been working since now, but I cannot figure out why it doesn't !

Thanks in advance ! :-)

Subject: Problem loading data back into fields

From: Steven_Lord

Date: 10 Dec, 2012 03:40:14

Message: 5 of 5



"Matt " <mathieu.horsky@gmail.com> wrote in message
news:k9vlht$kts$1@newscl01ah.mathworks.com...
> So I am giving a bit more details. If I am using the same method as the
> tutorial below, it works :
>
> http://blogs.mathworks.com/videos/2008/10/31/video-saving-the-state-of-a-gui/
>
> The thing is that I'm allowing the user to choose a name for the file.
> Here is my code :
>
> ------------------------------------
> function savedata_box_Callback(hObject, eventdata, handles)
> savename = uiputfile(...
> {'*.mat','MATLAB data file (*.mat)';}, ...
> 'Save the file as...');
> assignin('base', 'savename', savename);
> state.val1 = get(handles.val1_box, 'string');
> save (savename)
>
> function loaddata_box_Callback(hObject, eventdata, handles)
> loadname = uigetfile( ...
> {'*.mat','MATLAB data file (*.mat)';}, ...
> 'Select a data file...');
> load (loadname)
> set(handles.val1_box, 'string', state.val1);
> ------------------------------------
>
> Again it has been working since now, but I cannot figure out why it
> doesn't !

1) Define "it doesn't [work]" -- does it throw an error (and if so, which
one)? Does it throw a warning? Does it give you results other than what you
expect?

2) DO NOT call LOAD without an output argument inside a function. Doing so
is a good way to overwrite variables that already exist in your function's
workspace (in this case, the handles structure in particular. That's kind of
a Bad Thing.)

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us