0

My interest is to display image in axes, I've 2 GUI's input_window and fig5. In my former GUI I've used one axes to display image using uigetfile ,

axes(handles.axes1);
imshow(fname);

Now by pressing pushbutton in 1st GUI it switches to fig5 GUI, where I've used so many axes to display multiple images, also i want to display fname image in one axes and it should automatically get displayed in fig5 GUI. For this I've used same above codes in Fig5_OpeningFcn

axes(handles.axes1);
imshow(fname);

I'm getting error like Undefined function or variable 'fname'. please help me how to pass variables between GUI's

ford
  • 10,687
  • 3
  • 47
  • 54
Chethan
  • 213
  • 3
  • 7
  • 19

1 Answers1

0

You could use setappdata and getappdata, like so:

% In the first figure:
setappdata(0, 'fname', fname);
% Show the second figure...


% In the second figure:
fname = getappdata(0, 'fname');
% Clear the appdata
setappdata(0, 'fname', '');
% Do stuff with fname
wakjah
  • 4,541
  • 1
  • 18
  • 23
  • Where should i copy `setappdata(0, 'fname', fname);` in my first GUI? i copied in `Input_window_OpeningFcn` and I'm getting error `Undefined function or variable 'fname'` – Chethan Apr 13 '13 at 18:04
  • i've used `setappdata(Fig5, 'fname', fname);` in `Input_window_OpeningFcn` and `fname = getappdata(Input_window, 'fname');` in `Fig5_OpeningFcn`. I got a new ERROR and I'm not getting why recursion has reached limit, a bit afraid of this error `Maximum recursion limit of 500 reached. Use set(0,'RecursionLimit',N) to change the limit. Be aware that exceeding your available stack space can crash MATLAB and/or your computer. Error in ==> isprop` – Chethan Apr 13 '13 at 18:22
  • This means something is calling itself indefinitely. This could be happening because, e.g., function A is calling function B, and function B is calling A, which calls B, which calls A, etc. Perhaps each UI is trying to open the other? – wakjah Apr 14 '13 at 11:39
  • Exactly, Then using `setappdata` and `getappdata` how can i pass variable between GUI's? Where should i copy `setappdata(0, 'fname', fname);` in my first GUI? – Chethan Apr 14 '13 at 14:15
  • Well you need to `setappdata` before you `getappdata`. So `setappdata` at some point before you need the variable in the second GUI (whenever it becomes available) and then `getappdata` afterwards. If both GUIs need the variable as soon as they open, then do your `setappdata` before you open either of them. – wakjah Apr 14 '13 at 15:46
  • What does `0` represents in `setappdata(0, 'fname', fname);` – Chethan Apr 14 '13 at 17:06
  • You should read [the documentation](http://www.mathworks.co.uk/help/matlab/ref/setappdata.html). `0` here means it's the "global" app data. – wakjah Apr 14 '13 at 17:19