views:

72

answers:

1

Hi everyone, I have such code:

a=5;
b=a;
c=10;
u = (0:0.05*pi:2*pi)'; %'
v = [0:0.05*pi:2*pi];
X = a*sin(u)*cos(v);
Y = a*sin(u)*sin(v);
Z = c*cos(u)*ones(size(v));
Z(Z>0)=0; % cut upper
V1=4/3*pi*a*b*c;
d=1/2;
e=2^d;
a2=a/e;
b2=a/e;
c2=c;
V2=4/3*pi*a2*b2*c2;
X2 = a2*sin(u)*cos(v);%-2.5;
Y2 = b2*sin(u)*sin(v);
Z2 = c2*cos(u)*ones(size(v));%+0.25;
Z2(Z2>0)=0; % cut
h=1/3;

for j = 1:20
 k1=(sin(pi*j/20)+0.5)^h;
    a=a*k1;
    c=c*k1;
    X = a*sin(u)*cos(v);
    Y = a*sin(u)*sin(v);
    Z = c*cos(u)*ones(size(v));
    Z(Z>0)=0;
        a2=a2*k1;
    b2=a2*k1;
    c2=c2*k1;
    X2 = a2*sin(u)*cos(v)+5;%-2.5;
    Y2 = b2*sin(u)*sin(v);
    Z2 = c2*cos(u)*ones(size(v));%+0.25;
    Z2(Z2>0)=0;

    hS1=surf(X,Y,Z);
    alpha(.11)
    hold on
    hS2=surf(X2,Y2,Z2);
    hold off
        axis([-20 20 -20 20 -20 20]);
    F(j) = getframe;
    end
    movie(F,4)

I have to input parameters a,b,c from the keyboard. I've made GUI & tried to do it by using "Edit text" with a function below, but it's not working((. I can't understand what's the problem with it.

function a_edit_Callback(hObject, eventdata, handles)
user_entry = str2double(get(hObject,'string'));...
a=user_entry;

A: 

The problem is that your callback function executing your code is not 'seeing' the parameters you defined in your edit text callbacks. You need to establish your variables in the subfunction, since they aren't global.

Using guide, set up a uicontrol button to click when you've entered your parameters into your uicontrol edit text boxes. Under the callback of your button, place your above code, with the following at the top:

a=str2double(get(handles.a_edit,'String'));
b=str2double(get(handles.b_edit,'String'));
c=str2double(get(handles.c_edit,'String'));

This will pull in the current strings of your edit text uicontrols. (Assuming you've assigned the tag format x_edit for each of the edit text boxes in guide.)

EDIT:

Open the figure you already created with the edit text boxes. Next, check to make sure each of your text boxes have the tag a_edit, b_edit, c_edit by using the property inspector. Then create a button using guide, and open the property inspector by double clicking on it. Find the 'tag' field, and name it run. Save your figure, and open the corresponding M-file.

Next, find the line with run_Callback(hObject, eventdata, handles). Place the following under it:

a=str2double(get(handles.a_edit,'String'));
b=str2double(get(handles.b_edit,'String'));
c=str2double(get(handles.c_edit,'String'));
%# Add the rest of your code from above verbatim, minus the first three lines

This should be the ONLY code you add to the auto-generated M-file - don't mess with anything else until you get this much working. If you don't want the animation popping up randomly in your figure window, you can add a set of axes using guide as well.

Doresoom
I did it the way you suggested, but the same error occures:??? Reference to a cleared variable user_a.Error in ==> GUI_1>Ok_btn_Callback at 266a=user_a;
Kate
variable user_a=str2double(get(handles.a_edit,'String'))
Kate
Under which callback did you place that line? The only callback that needs any code under it is your 'run' button callback.
Doresoom
Thanks a lot, I found a mistake)
Kate