how to pass array using get, set from one gui to other?

hii I have 2 gui.In main gui I have passed array of images like dis-
> for i=1:120
> > imgs{i} = imread( sprintf('%d.jpg',idx(i) ));
> > set(0,'userdata',imgs{i})
> end
In sub gui I hav used this code to get images
>for i=21:60
> > imgs{i}= get(0,'userdata');
> end
> axes(handles.axes28)
> imshow(imgs[21])
> axes(handles.axes29)
> imshow(imgs[22]) . . . everytime I am getting 120 th image plotted in all 60 output axis... Whats wrong here pls clarify.

Respuestas (1)

Jan
Jan el 28 de Abr. de 2015
In your code the UserData of the root object are overwritten 119 times:
for i = 1:120
imgs{i} = imread( sprintf('%d.jpg',idx(i) ));
set(0,'userdata',imgs{i})
end
Better use:
for i = 1:120
imgs{i} = imread( sprintf('%d.jpg',idx(i) ));
end
set(0,'userdata',imgs)
Now the cell imgs is stored in the UserData.
Btw., the Userdata of the root object are equivalent to using global variables. So einer rely on globals directly or consider the serious warnings about globals and avoid this dirty trick. Better store the data in the UserData or ApplicationData of a GUI instead of the root object.

4 comentarios

preeti
preeti el 28 de Abr. de 2015
Editada: preeti el 28 de Abr. de 2015
thanks @Jan Simon but i dunt knw how to use global variables in GUI please elaborate it with same example as above for arrays .
Jan
Jan el 28 de Abr. de 2015
Simply use the figure handle instead of the root object 0. The topic of sharing data between callbacks has been discussed many times in this forum and a search will be successful.
Adam
Adam el 28 de Abr. de 2015
Be aware though that data stored on the handles of one GUI is not automatically accessible within another GUI.
Probably using findobj you can yoik the handles of one GUI out to use in another, but I've never used such a ghastly approach to having two GUIs communicate with each other so I can't remember
preeti
preeti el 28 de Abr. de 2015
thanks @Jan Simon and @Adam wil find it out..:)

Iniciar sesión para comentar.

Categorías

Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 28 de Abr. de 2015

Comentada:

el 28 de Abr. de 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by