excuse como se hace para aumentar el slider de 1 en 1, example 0, 1, 2 ………. 100 68. on 09 Oct 2009 at 1:25 pm 68Zane Montgomery Anonymous,
Si entiende ingles, el comentario #32 describe esto (yo creo). Lo te tratare explicar. En la seccion ―Writing the Code for the GUI‖ cambie su funccion a:
%obtains the slider value from the slider component sliderValue = get(handles.slider1,'Value');
%nueva linea%
sliderValue=round(sliderValue);
%puts the slider value into the edit text component
set(handles.slider_editText,'String', num2str(sliderValue));
% Update handles structure guidata(hObject, handles);
Ojala que entienda. Buena suerte.
69. on 11 Oct 2009 at 6:21 pm 69Jeet Wonderful tutorial!
Quan, I have two variables in a quadratic equation, x & y (quatratic in x) and x has range of values. I am able to produce a plot for the equation now (thanks to your tutorial again) and believe that we can set slider for x. But could not club both (plotting and slider) in the same GUI (I am a novice matlab user). Can you help me here?
The equation is: P = n*x^2+x+n*x*y+c ; (n and c are constants) where x = -2:0.01:2
What actually I want to display is changing characteristics of the curve ?P‘ with change in value of x. Tons thanks in advance
70. Jeet,
on 12 Oct 2009 at 10:47 am 70Zane Montgomery This is very doable. You need to do 2 main things: Change the limits on your slider, and then plot your function. Changing limits:
This can be done in the inspector if you have your slider as the active panel (just click on the slider tool, double click to get inspector to pop up). Find min/max values and set those to -2/2.
This can also be done with commands:
set(handles.slider1,'Max',[2]) set(handles.slider1,'Min',[-2])
Now your sliderValue is your ?x‘ that you change. Plotting the function:
I made a separate axes tool in the GUI editor to plot this. In the slider1_Callback and the editText1_Callback functions, you need to get the slidervalue and the plotting function, and create some y independent variable vector as seen below
%slider1_Callback function
%obtains the slider value from the slider component sliderValue = get(handles.slider1,'Value');
%puts the slider value into the edit text component
set(handles.slider_editText,'String', num2str(sliderValue)); n=1; c=0; y=0:100;
P = n*sliderValue^2+sliderValue+n*sliderValue*y+c; plot(handles.axes1, P,y)
hold on % this is fun to watch the progression of your plotted variable. % Not needed though
% Update handles structure guidata(hObject, handles);
You‘ll have to update the editText ranges of 0–>100 to -2–>2 as well. This is a linear function since you are taking discrete steps in ?x‘ and plotting over ?y‘. The same can be done for parabolas, but make sure you use …y.^2+c instead of just …y^2+c
happy hacking, Zane 71. on 12 Oct 2009 at 5:17 pm 71Jeet Genious! Thank you Zane! 72. on 26 Oct 2009 at 10:17 am 72stLeth Hi, everyone:
I have a question need help. I want to set up a static text to display slider‘s min value.
However, when I type:
set(handles.text1, ?String‘, get(handles.slider1, ?Min‘); An error message appear:
??? Attempt to reference field of non-structure array. Could anyone help me to solve this problem? Thank you.
73. on 26 Oct 2009 at 10:45 am 73Zane Montgomery You‘re close stLeth, The min value is in double format, you want it to be string format to put it into ?String‘. Also you‘re missing a parenthetical. Try this: set(handles.text1, ‘String’, num2str(get(handles.slider1, ‘Min’))); 74. on 26 Oct 2009 at 11:26 am 74stLeth Thank you, Zane:
I correct my code to: set(handles.text1, ?String‘, get(handles.slider1, ?Min)); Same error message appears again: ??? Attempt to reference field of non-structure array.
I put the set() code inside text1_CreateFcn(hObject, eventdata, handles) function. Is this a mistake? Many thanks.
75. on 26 Oct 2009 at 11:39 am 75stLeth Hi, Zane: I tried your code, but same error message appeared. Thank you. 76. on 26 Oct 2009 at 12:19 pm 76Zane Montgomery Yup, you‘re in the wrong function. You haven‘t established either your slider or static text fully when you call text1_CreateFcn…
You need to put that block of code I gave you in Callback functions for whatever buttons you want (slider, edit_text, etc)
77. on 26 Oct 2009 at 12:20 pm 77stLeth Hi, Zane: I move the code to slider1_Callback function. It works. Thank you. 78. on 26 Oct 2009 at 3:50 pm 78stLeth Hi, Zane:
How could I avoid hard coding the static text‘s value each time the slider‘s value changed? (For example, if I want to use static text to display slider‘s minimum value, I change the slider‘s ?Min‘ value and the static text will change as well.) Thank you for your help.
79. on 28 Oct 2009 at 12:46 am 79Bhavesh Shah thanks for this tutorial. its really helps in GUI programming. 80. on 05 Nov 2009 at 2:03 am 80Ishan Thank you bro…it really helped 81. on 05 Nov 2009 at 8:48 pm 81Ishan hey all,
相关推荐: