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:
GUI - save and load buttons

Subject: GUI - save and load buttons

From: Chris

Date: 9 Dec, 2008 19:36:02

Message: 1 of 1

Hi,
I watched a video by Doug Hull on using a save and load button in a GUI to remember settings, and this could be quite useful in a project I am taking. I thought it would be best to apply it to a small GUI I wrote to learn the principles behind GUI operations and I have got slightly stuck. Unfortunately, the file I downloaded from the top example on this page:
http://blogs.mathworks.com/videos/page/2/
throws up an error on line 42 which I don't understand.

I've taken the relevant snippets out that should illustrate where I am at without filling up this page too much! I can post the whole m file if necessary - is there a way to attach files to this thread?

Cheers,
Chris
------------------------------------------------------------------------------------------------
function gui1
fig=figure('name','My GUI','position',[360 500 160 140],'menubar','none');

m1=uicontrol(fig,...
    'style','pop',...
    'enable','on',...
    'string',{1,2,3,4,5,6,7,8,9},...
    'position',[20 110 30 5],...
    'callback',{@pop1cb},...
    'value',1);
b3=uicontrol(fig,...
    'style','pushbutton',...
    'string','Save',...
    'position',[20 10 40 15],...
    'callback',{@savebutton});
b4=uicontrol(fig,...
    'style','pushbutton',...
    'string','Load',...
    'position',[80 10 40 15],...
    'callback',{@loadbutton});

 function savebutton(source,eventdata);
        savestate(m1);
    end
    function loadbutton(source,eventdata);
        restorestate(m1);
    end
    function savestate(m1);
        state.m1=get(m1, 'value');
        
        save fig.mat state
    end
    function restorestate(m1);
        load 'fig.mat', 'state';
        
        set(m1, 'value', state.m1);
    end
end

Tags for this Thread

No tags are associated with 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