MATLAB time delay

Discussion in 'Programmer's Corner' started by ircommando, Aug 20, 2009.

  1. ircommando

    Thread Starter New Member

    Jun 17, 2009
    3
    0
    I am writing a simple program that repeats itself forever until the user stops it. It samples a waveform from an oscope and when one of the waveforms meets a certain criteria it stops the scope, saves the waveforms on all four channels, starts the scope back up, and starts over again. My question is how can I delay the repeated sampling of the "trigger" waveform.The wavefrom does not change that quickly so if I could sample it every 5-10 seconds that would save my computer from incessantly computing the trigger condition. The test could run for well over a day so giving the computer a break is probably a good thing. I bet there is a very simple solution to this, but I am a noobie to programming, and am still learning a lot of the basic tricks so any help is greatly appreciated. Thanks.:D
     
  2. ryta

    New Member

    Aug 27, 2009
    4
    0
    hi buddy you can do this by applying loop condition in it and just insert a condition such that which can execute your loop infinitely until that condition is satisfied.
     
    Last edited by a moderator: Aug 27, 2009
  3. prionkor

    New Member

    Jun 8, 2009
    7
    0
    You can try by infinite loop. Use while or for loop. Most commonly used loop for infinite loop is while. Here is a simple program which has a infinite while loop defined by while(1):

    i=0;
    while(1)
    i
    if i==1000
    break
    end
    i = i+1;
    end

    if statement is very important in infinite loop where in certain you have to break the loop. Otherwise the loop will never stops. I this case you will able to break the loop by pressing ctrl+c in PC or cmd+c in mac.

    Thanks.
     
  4. kaankarabulut

    New Member

    Oct 3, 2009
    3
    0
    you may be use 'clock' function. this function is return that your computer's time
    c = clock
    c = [year month day hour minute seconds]

    c =
    1.0e+003 *
    2.0090 0.0100 0.0040 0.0020 0.0110 0.0485
     
  5. ircommando

    Thread Starter New Member

    Jun 17, 2009
    3
    0
    Thanks to all that responded, but if anyone else looks at this and is new to MATLAB and not acquainted with its many functions, as I wasn't, I found that the easiest way to accomplish what I asked was to use the pause function somewhere in the while loop. pause(1) will cause execution of the M-file to stop for one second, pause(.1) will cause it to stop for .1 seconds, etc. Thanks again for responding.
     
Loading...