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

(GUI variable saving) guidata vs appdata

Asked by Voulgarakis Georgios on 4 Feb 2013

Dear all

I need your opinion on the matter. In order to allow the user to enter various parameters, my program has a GUI figure. The problem is that the user by interacting with my program, creates a big amount of data, which have to be stored and processed every time. My problem is that when the user hovers his mouse on my figure, I need to go trough a lot of these data.

So, saving where, these data, will ensure the maximum speed for my program? Should I go with the appdata, or with the guidata (saving the variable directly into the guihandle)?

Thanks in advance

0 Comments

Voulgarakis Georgios

Products

No products are associated with this question.

2 Answers

Answer by Sean de Wolski on 4 Feb 2013
Edited by Sean de Wolski on 4 Feb 2013
Accepted answer

guidata() Just uses setappdata() internally. That being said: setappdata() will be faster since you don't have the overhead of what's inside guidata().

3 Comments

Voulgarakis Georgios on 4 Feb 2013

I was expecting something like this. But on my program, when I work with appdata, when I timed it, (tic tac), it turned out that guidata was faster! (actually in my case, it was almost 7-10 times faster!)

Generally, one aspect of the the program, is that the user created new objects(data + axes object), that are placed in the main figure. And I have to find out where the cursor is, whenever he moves the cursor (WindowButtonMoveFcn). Which means that I do a for loop, trying to find if the position of the cursor, is within the bounds of any of the objects (axes) the user has placed.

worst case->nth found =>All objects had to be checked and compared

Any Ideas on how to improve?

Sean de Wolski on 4 Feb 2013

What appdata are you using when you use setappdata; and how are you timing it?

Sean de Wolski on 4 Feb 2013

Also, if you're really worried about timing and control, (which it sounds like you are!), ditch GUIDE and write the GUI programatically. GUIDE uses an older framework that is not necessarily speed or control optimized.

Using nested functions will get you this.

These examples will help you getting started:

http://www.mathworks.com/matlabcentral/fileexchange/24861-41-complete-gui-examples

Sean de Wolski
Answer by Jan Simon on 4 Feb 2013

GUIs live in the frequency domain of 10 Hz: Mouse clicks by the user, animated effects, waiting for update of the screen - GUIs are slow and that's ok, because they are useful for the slow visual reception by human.

When calculations should happen with a high speed, they should be decoupled from the GUI, such that the decision between guidata and setappdata does not matter at all. Processing a lot of data whenever the mouse is moved is prone to problems caused by the latency. Unfortunately such an uncoupling is not easy in Matlab, because Matlab runs a single thread only.

You do not have to search for the spatial objects dynamically. The areas belonging to certain objects change only when you move the 3D or 2D scene and when new objects are added.

Finally I'm convinced that getappdata is faster than guidata for the reasons Sean has posted already. But the small overhead of both functions should not matter, when you avoid to call them thousands of times for one processing step. Calling them once should be sufficient, when the data are stored in a useful structure.

4 Comments

Jan Simon on 5 Feb 2013

And in which phase do you encounter the timing problems?

Voulgarakis Georgios on 5 Feb 2013

@Sean de Wolski

thanks for the link. What it shows is pretty much what I have done. :)

The procedure for drag n drop is grab(replace buttondownfcn), drag(replace windowbuttonmotionfcn) and release (replace buttonupfcn).

What I am trying to achieve though, is even before the user has clicked on an object(axes) (which event would trigger the buttondownfcn of the axes), I would like that I somehow know, where the cursor is over.

@JanSimon

This is where, in order to achieve it, in the the standard windowbuttondownfcn (before having it replaced by the drag), I do a check to see if the cursor is whithin the bounds of any of the objects. This calculation (which is done for every cursor movement) is not going very fast (especially if I have a lot of axes!).

Jan Simon

Contact us