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:
Which is better structure pushed onto a GUIDATA or structure pushed on APPDATA

Subject: Which is better structure pushed onto a GUIDATA or structure pushed on APPDATA

From: Shriniket Sarkar

Date: 6 Oct, 2010 21:01:19

Message: 1 of 5

Hello,
        I have a huge structure which currently I am storing using the guidata command to attach it to the GUI handle every time i hope between functions.
This structure has like 3 levels where in I use for ex:
handles.Level1.Attributes or
handles.Level1.Level2.Attributes
to access or store the variable values which i often need in various functions. I have like 30 attributes in each level roughly and some of them store certain arrays too.
       Ques 1:
Would you suggest that I make a matrix in which i shall save values of all these variables and write my code accordingly to access the values from this matrix instead of the structure being pushed to the GUI DATA and storing the matrix on disk? i.e. should i save and load this structure every time i need it ? Is load and save a costly operation as compared to holding the data on the GUI?
     Ques 2:
Which one is better ? GUIDATA or APPDATA to use in such a scenario?Or are there any other alternatives?
    Ques 3:
Will saving this structure or the matrix onto the guidata affect rendering performance of the GUI? I mean to ask will such a huge structure make the GUI slower and little less responsive?
Any clues or hints are highly appreciable.

Subject: Which is better structure pushed onto a GUIDATA or structure pushed on APPDATA

From: Sean

Date: 6 Oct, 2010 21:23:20

Message: 2 of 5

"Shriniket Sarkar" <shriniketsarkar@gmail.com> wrote in message <i8io2v$7l7$1@fred.mathworks.com>...
> Hello,
> I have a huge structure which currently I am storing using the guidata command to attach it to the GUI handle every time i hope between functions.
> This structure has like 3 levels where in I use for ex:
> handles.Level1.Attributes or
> handles.Level1.Level2.Attributes
> to access or store the variable values which i often need in various functions. I have like 30 attributes in each level roughly and some of them store certain arrays too.
> Ques 1:
> Would you suggest that I make a matrix in which i shall save values of all these variables and write my code accordingly to access the values from this matrix instead of the structure being pushed to the GUI DATA and storing the matrix on disk? i.e. should i save and load this structure every time i need it ? Is load and save a costly operation as compared to holding the data on the GUI?
> Ques 2:
> Which one is better ? GUIDATA or APPDATA to use in such a scenario?Or are there any other alternatives?
> Ques 3:
> Will saving this structure or the matrix onto the guidata affect rendering performance of the GUI? I mean to ask will such a huge structure make the GUI slower and little less responsive?
> Any clues or hints are highly appreciable.

Personally I recommend staying as far away from GUIDATA as possible all of the time; APPDATA all the way! (that's just my opinion)

As far as how to store it:
Are there pieces that you use more often? If so you can store them separately so when you call them it doesn't have to retrieve quite as much data, some of which won't be used.

Subject: Which is better structure pushed onto a GUIDATA or structure pushed on APPDATA

From: Shriniket Sarkar

Date: 6 Oct, 2010 21:42:04

Message: 3 of 5

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i8ipc8$3hf$1@fred.mathworks.com>...
> "Shriniket Sarkar" <shriniketsarkar@gmail.com> wrote in message <i8io2v$7l7$1@fred.mathworks.com>...
> > Hello,
> > I have a huge structure which currently I am storing using the guidata command to attach it to the GUI handle every time i hope between functions.
> > This structure has like 3 levels where in I use for ex:
> > handles.Level1.Attributes or
> > handles.Level1.Level2.Attributes
> > to access or store the variable values which i often need in various functions. I have like 30 attributes in each level roughly and some of them store certain arrays too.
> > Ques 1:
> > Would you suggest that I make a matrix in which i shall save values of all these variables and write my code accordingly to access the values from this matrix instead of the structure being pushed to the GUI DATA and storing the matrix on disk? i.e. should i save and load this structure every time i need it ? Is load and save a costly operation as compared to holding the data on the GUI?
> > Ques 2:
> > Which one is better ? GUIDATA or APPDATA to use in such a scenario?Or are there any other alternatives?
> > Ques 3:
> > Will saving this structure or the matrix onto the guidata affect rendering performance of the GUI? I mean to ask will such a huge structure make the GUI slower and little less responsive?
> > Any clues or hints are highly appreciable.
>
> Personally I recommend staying as far away from GUIDATA as possible all of the time; APPDATA all the way! (that's just my opinion)
>
> As far as how to store it:
> Are there pieces that you use more often? If so you can store them separately so when you call them it doesn't have to retrieve quite as much data, some of which won't be used.


Ok i get what you intend to convey but isn't the APP-DATA also attached with the GUI handle as such ? I mean when we set it and get it we set or get it from the GUI right ?
Well and yes i have to use most part of that structure very often. Had it not been the case then I would have simply saved it onto the disk and loaded it when needed.

Do you know about any data-type in matlab which we can use as a drop-box which stays in the main memory and doesn't get pushed to the disk? I mean to say some constant / static variable which could hold my structure even while i hope between functions ? But it should be separate than the GUI handle which stays persistent.
Any hints on this ?

Subject: Which is better structure pushed onto a GUIDATA or structure pushed on APPDATA

From: Sean

Date: 6 Oct, 2010 21:52:04

Message: 4 of 5


> Ok i get what you intend to convey but isn't the APP-DATA also attached with the GUI handle as such ? I mean when we set it and get it we set or get it from the GUI right ?
> Well and yes i have to use most part of that structure very often. Had it not been the case then I would have simply saved it onto the disk and loaded it when needed.
>
> Do you know about any data-type in matlab which we can use as a drop-box which stays in the main memory and doesn't get pushed to the disk? I mean to say some constant / static variable which could hold my structure even while i hope between functions ? But it should be separate than the GUI handle which stays persistent.
> Any hints on this ?

To your first question, I don't believe so. Not if you do this:

setappdata(0,'your_structure',your_structure); % Set it to the root directory, not the handles of the GUI (I may very well be incorrect on this)

There are persistent variables that you could use, though it's dangerous is you're updating the structure elsewhere.

Subject: Which is better structure pushed onto a GUIDATA or structure pushed on APPDATA

From: Jan Simon

Date: 6 Oct, 2010 23:49:04

Message: 5 of 5

Dear Shriniket,

look in the code of GUIDATA. There you find, that the values are stored by SETAPPDATA in the GUI. So both methods are very similar.
The same for UserData: While SETAPPDATA stores the variables in substructs of the figures ApplicationData property - which is a struct, the UserData are stored directly as variable. Therefore these are equivalent:
  setappdata(DlgH, 'Name', Value)
and
  UD = get(DlgH, 'UserData');
  UD.(Name) = Value;
  set(DlgH, 'UserData', UD);

I'm using UserData for static values, e.g. lists of handles, and APPDATA for dynamic data as last applied colors, paths, etc. But I cannot see a drawback to do it the other way around, or using GUIDATA for both.

Kind regards, Jan

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