Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
problem with while and if

Subject: problem with while and if

From: nolwenn Guillemot

Date: 20 Jul, 2010 12:40:21

Message: 1 of 5

Hi,
I have to use a while loop and inside a test with an if. I know it's bad but I don't have the choice. If I don't write a pause or a drawnow between the two loop, MatLab crash. In fact, at the end of my loop, I refresh a figure. It takes too much time and I want it faster. I had a "drawnow" after my "set" but this does the same thing that a pause and apparently I need a pause between my two loops.

There is my code :

while(ishandle(plotHandle))
      pause(0.01);
 
     if DSP_transfert.start==1,
    
            treatment;

            %Display---------------------------------------------------
   
            if DSP_transfert.freeze==0
                   set(plotHandle,'YDATA',Buffer);
                   set(plotHandle1,'YDATA',Buffer2);
           end
    end
end


The ideal would be to display the figure in parrallel but I think I don't have the Matlab parallel thing beacause matlabpool does not exist. If some body could help me ... thank you very much

Subject: problem with while and if

From: Sean

Date: 20 Jul, 2010 13:20:20

Message: 2 of 5

"nolwenn Guillemot" <nolwenn.guillemot@hotmail.fr> wrote in message <i245fl$i9e$1@fred.mathworks.com>...
> Hi,
> I have to use a while loop and inside a test with an if. I know it's bad but I don't have the choice. If I don't write a pause or a drawnow between the two loop, MatLab crash. In fact, at the end of my loop, I refresh a figure. It takes too much time and I want it faster. I had a "drawnow" after my "set" but this does the same thing that a pause and apparently I need a pause between my two loops.
>
> There is my code :
>
> while(ishandle(plotHandle))
> pause(0.01);
>
> if DSP_transfert.start==1,
>
> treatment;
>
> %Display---------------------------------------------------
>
> if DSP_transfert.freeze==0
> set(plotHandle,'YDATA',Buffer);
> set(plotHandle1,'YDATA',Buffer2);
> end
> end
> end
>

Why do you need a pause; to slow it down? A drawnow is necessary for the figure to update; yes. What are you doing to have to refresh the figure every few seconds? I'll bet there's a better way around that.


> The ideal would be to display the figure in parrallel but I think I don't have the Matlab parallel thing beacause matlabpool does not exist. If some body could help me ... thank you very much

This is very much doable without the parallel computing toolbox. I don't think you're completely understanding how the figure works.

Subject: problem with while and if

From: nolwenn Guillemot

Date: 20 Jul, 2010 14:22:37

Message: 3 of 5

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i247qk$j4i$1@fred.mathworks.com>...
> "nolwenn Guillemot" <nolwenn.guillemot@hotmail.fr> wrote in message <i245fl$i9e$1@fred.mathworks.com>...
> > Hi,
> > I have to use a while loop and inside a test with an if. I know it's bad but I don't have the choice. If I don't write a pause or a drawnow between the two loop, MatLab crash. In fact, at the end of my loop, I refresh a figure. It takes too much time and I want it faster. I had a "drawnow" after my "set" but this does the same thing that a pause and apparently I need a pause between my two loops.
> >
> > There is my code :
> >
> > while(ishandle(plotHandle))
> > pause(0.01);
> >
> > if DSP_transfert.start==1,
> >
> > treatment;
> >
> > %Display---------------------------------------------------
> >
> > if DSP_transfert.freeze==0
> > set(plotHandle,'YDATA',Buffer);
> > set(plotHandle1,'YDATA',Buffer2);
> > end
> > end
> > end
> >
>
> Why do you need a pause; to slow it down? A drawnow is necessary for the figure to update; yes. What are you doing to have to refresh the figure every few seconds? I'll bet there's a better way around that.
>
>
> > The ideal would be to display the figure in parrallel but I think I don't have the Matlab parallel thing beacause matlabpool does not exist. If some body could help me ... thank you very much
>
> This is very much doable without the parallel computing toolbox. I don't think you're completely understanding how the figure works.


I agree with you I am a little lost.
If I do not write the "pause" after the while, MatLab could not do anything, it crash, and I have to force it close. When I write "pause" the figure is refresh during the pause so I delete the drawnow to not have a supplementary pause.

To answer you, I use this program to voice data acqusition. The voice is modified on Matlab and write on headphones. The executive time have to be very short because the subject does not have to hear the latency time. We want to see the spectrum of the voice in real time.

Thanks for your answer.

Subject: problem with while and if

From: Sean

Date: 20 Jul, 2010 15:38:05

Message: 4 of 5


> I agree with you I am a little lost.
> If I do not write the "pause" after the while, MatLab could not do anything, it crash, and I have to force it close. When I write "pause" the figure is refresh during the pause so I delete the drawnow to not have a supplementary pause.
>
> To answer you, I use this program to voice data acqusition. The voice is modified on Matlab and write on headphones. The executive time have to be very short because the subject does not have to hear the latency time. We want to see the spectrum of the voice in real time.
>
> Thanks for your answer.

Do you have the data acquisition toolbox?
Also take a peek at timers
>>doc timer

Subject: problem with while and if

From: nolwenn Guillemot

Date: 21 Jul, 2010 14:26:05

Message: 5 of 5

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i24fst$hb3$1@fred.mathworks.com>...
>
> > I agree with you I am a little lost.
> > If I do not write the "pause" after the while, MatLab could not do anything, it crash, and I have to force it close. When I write "pause" the figure is refresh during the pause so I delete the drawnow to not have a supplementary pause.
> >
> > To answer you, I use this program to voice data acqusition. The voice is modified on Matlab and write on headphones. The executive time have to be very short because the subject does not have to hear the latency time. We want to see the spectrum of the voice in real time.
> >
> > Thanks for your answer.
>
> Do you have the data acquisition toolbox?
> Also take a peek at timers
> >>doc timer

I'll try the data acquisition toolbox.
I realize MatLab crashes when the if's expression is wrong in infinite while loop. I don't really understand why ...

Thanks for all your answers.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us