0

I am now using Matlab GUI and have problem during accessing return values from a function which is set by set().

Situation:
I set the windowMotionFcn as below:

set(gcf,'WindowButtonMotionFcn',@test);

Function 'test' can return 2 variables (named as var1 and var2).But I dont know how to store them...
I have searched in the Internet and could not find any way.

How should I write?

Thank you for your help and kind attention.

Shubham Bhave
  • 383
  • 6
  • 17
Myrick Chow
  • 332
  • 1
  • 6
  • 16
  • How do you want the data stored? Do you want to utilize it in another callback? Do you want to display it in the output panel? Do you want to save it to a file? – sco1 Jul 30 '14 at 12:14
  • have you tried `set(gcf, 'WindowButtonMotionFcn', [@test])`, or `set(gcf, 'WindowButtonMotionFcn', {@test})` ? – JayInNyc Jul 30 '14 at 12:16
  • Hi @excaza, I want to store my variables like: [storeVar1 storeVar2] = test Thx a lot – Myrick Chow Jul 31 '14 at 01:06
  • Hi @JayInNyc , I tried your code before but it did not work. The {} is for passing input parameters to test function. Thank you for your nice help. :) – Myrick Chow Jul 31 '14 at 01:13

1 Answers1

0

I think that what you want to do is to return a value from the callback function. And regarding returning a value from a callback I am not sure that is possible. I found an old article from matlab newsreader. I think your problem could be similar.

However, if you have a matlab GUIDE GUI, there is a way to return a value from a gui. It is described in a matlab tutorial in matlab central: advanced-getting-an-output-from-a-guide-gui. What you must do is to modify your CloseRequestFcn and your OutputFcn.

Another way, which should work is using global variables. A global varable exist in the global workspace. That means that it can be seen and accessed by every function in matlab. Global variables are in most cases not recommended, but if no other solution exists they may be necessary. Just make sure to document them, so that the next person to take over your code knows that they are there. Also make sure to select a good name for the globals, like gblMyVar so there can be no confusion that the variable is global.

patrik
  • 4,506
  • 6
  • 24
  • 48