Return to index: [Subject] [Thread] [Date] [Author]

Re: Question !!

[Subject Prev][Subject Next][Thread Prev][Thread Next]
i don't know much about matlab but i have used other programming languages, here are my 2 suggestions:
 
1.  embed a statement inside your while loop (probably near where you are incrementing your counter) that looks for the current state of the "stop" button.  you may not be able to get this exactly where you want it but it would be within 1 iteration of the loop (as opposed to an infinite loop?).
 
2.  rewrite / rethink how this program works.  it seems strange to set up a function and then require the user to stop it while the function is being executed.  if you are trying to "converge" on a solution, maybe you can ask the user how many iterations he would like to use (then change the while statement to a "for" statement) or ask the user what is an expectable percentage to be within (then embed an error checking function into the while statement).
 
good luck, hth
 
da 
----- Original Message -----
Sent: March 08, 2002 10:37 AM
Subject: Question !!

Ladies and Gentlemn,
 
I'm trying to finish my Technical Report and am having
some trouble writing code. I am a pitiful code writer. I'm using MATLAB and
it's object orientated.

Attached is a text file of my function 'run'. I'm building a Graphical User
Interface in MATLAB and have 3 basic buttons that make it work:

1) a Slider - allows user input of an angle and sets the value = 'ang'.

2) the Start button - calls the function 'run' (attached) using the value
previously determined for 'ang'

3) the Stop button - will someday STOP my program from running.

I'm trying to find a way of stoping the loop within the function 'run' from
executing when the 'Stop' button is clicked. I'm not sure what to do and and
I'm not sure if you need to know MATLAB to figure that out.

Right now my function contains a loop and runs as long as stop = 'START'. I
define this outside the loop. While the loop is running, I want to click the
Stop button on my GUI and reset stop = 'STOP'. I can do this within the code
of the button but it doesn't change the value already set before the loop
begins.

Any suggestions?
 
Thanx in advance for your time!!
 
function run(ang)
 
[x,y,z]=sphere(20);
R=Ry(ang);
[x,y,z]=transform(x,y,z,R);
l=[0,0,1.3;0,0,-1.3];
a=l(:,1);
b=l(:,2);
d=l(:,3);
[a,b,d]=transform(a,b,d,R);
n=[0,0,1.2;0,0,-1.2];
R=Rz(pi/18);
stop='START';
i=1;
hold;
while stop=='START';
    [x,y,z]=transform(x,y,z,R);
    [a,b,d]=transform(a,b,d,R);
    colormap([127/255 1 212/255]);
    surf(x,y,z);
    axis equal;
    axis([-2 2 -2 2 -2 2]);
    hold;
    axis off;
    plot3(a,b,d,'r');
    plot3(n(:,1),n(:,2),n(:,3));
    view(0,0);
    Q(i)=getframe;
    hold;
    i=i+1;
 end;