make history

Hello,
I have 2 popupmenu in my figure. one popupmenu have some strings. I want to make history when i chosen one of them. how i can do it..?? when i chose a string in popupmenu, the last history still there..
thanks.. :)

2 comentarios

Jan
Jan el 9 de Mzo. de 2012
What is "make history"? What is the 2nd popup used for? Which last history is still where?
Rahma Yeni
Rahma Yeni el 10 de Mzo. de 2012
I'm sorry, maybe my explanation convoluted.. :)
so, i illustrate my question in this picture..
http://www.flickr.com/photos/rye_ni/6822456324/in/photostream
I hope your answer Sir..
Thanks before... :)

Iniciar sesión para comentar.

 Respuesta aceptada

Chandra Kurniawan
Chandra Kurniawan el 10 de Mzo. de 2012

1 voto

Hi, Rahma
I have seen your picture.
I think I cannot do it with your way.
Imagine if we have A-m-5 in 1st component and we also have c in 2nd component.
The pushbutton cannot decide which one must be stored in history, right?
So, I think we need 2 pushbutton to perform this. One in 1st component and another one in 2nd component.
The figure is shown below :
And the code :
In openingfcn
function untitled_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
handles.cnt = 0;
handles.history = {};
handles.p1str = {'Process1','A','B','C','D','E'};
handles.p2str = {'Process2','m','n'};
handles.p4str = {'Process4','a','b','c'};
set(handles.popupmenu1,'string',handles.p1str);
set(handles.popupmenu2,'string',handles.p2str);
set(handles.popupmenu3,'string',handles.p4str);
set(handles.slider1,'value',0,'sliderstep',[.05 .05]);
guidata(hObject, handles);
In slider1 callback
function slider1_Callback(hObject, eventdata, handles)
val = get(handles.slider1,'value');
val = round(val*20);
set(handles.text5,'string',num2str(val));
In pushbutton1 callback
function pushbutton1_Callback(hObject, eventdata, handles)
p1val = get(handles.popupmenu1,'value');
p2val = get(handles.popupmenu2,'value');
p3val = get(handles.slider1,'value');
p3val = round(20*p3val);
if (p1val > 1) & (p2val > 1)
handles.cnt = handles.cnt + 1;
histstr = horzcat(handles.p1str{p1val},', ',...
handles.p2str{p2val},', ',...
num2str(p3val));
handles.history{handles.cnt} = histstr;
set(handles.listbox1,'string',handles.history);
end
guidata(hObject,handles
In pushbutton2 callback
function pushbutton2_Callback(hObject, eventdata, handles)
p4val = get(handles.popupmenu3,'value');
if p4val > 1
handles.cnt = handles.cnt + 1;
histstr = handles.p4str{p4val};
handles.history{handles.cnt} = histstr;
set(handles.listbox1,'string',handles.history);
end
guidata(hObject,handles);
You can also download the file and do modification on it for your purpose.
I hope this works!

6 comentarios

Rahma Yeni
Rahma Yeni el 10 de Mzo. de 2012
but, the string of PopupMenu has been included by GUI. when i try the code, the string of PopupMenu be empty .. it became ' , , 2'.. how can I get the string of PopupMenu that I have made ..?
Chandra Kurniawan
Chandra Kurniawan el 10 de Mzo. de 2012
popstr = get(handles.popupmenu1,'string')
But this command returns all strings included in the popupmenu1.
You cannot directly get the choosen string from the popupmenu1, you should get the index first by :
popval = get(handles.popupmenu1,'value')
then followed by :
popslc = popstr{popval}
Rahma Yeni
Rahma Yeni el 10 de Mzo. de 2012
so far, the code that you give running well ..
but there is one more problem ..
I use two figures on this project ..
all previous code in figure 2 .. I used to like this http://www.mathworks.com/matlabcentral/answers/29639-linking-guis-in-matlab ..
why the code to display history, always error on the first time running ..?? but when i minimize the figure, then I run again using F5, the history can be appear ...
Chandra Kurniawan
Chandra Kurniawan el 10 de Mzo. de 2012
please describe it clearly.
so, in the first GUI you have a pushbutton to link the second GUI?
Rahma Yeni
Rahma Yeni el 10 de Mzo. de 2012
sorry... :)
yes,, in the first GUI i have a pushbutton to link the second GUI..
image in first GUI move to second GUI..
but, when i do 'make history', the choices are not appear in history list ..
it is the message:
??? Reference to non-existent field 'cnt'.
But, when i minimize the figure, then i run it again, the choices appear to history list..
Rahma Yeni
Rahma Yeni el 10 de Mzo. de 2012
like make history before, but i have the other example..
http://www.flickr.com/photos/rye_ni/6969686871/
where, string of 'b' and 'c' take the value from their text field. how i can make history like before..?? cause, one of the process have different text field..
thanks before Mr. Chandra.. :)
nice for your answer..

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Entering Commands en Centro de ayuda y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by