Can I add a force stop condition in a loop

In summary, the conversation discusses controlling a Keithley current source with MATLAB and the possibility of adding a condition to turn off the device if the loop is force stopped. The suggested solution is to use the MATLAB function onCleanup.
  • #1
liran avraham
7
0
i have keithley currnet source that i control with matlab, inside a loop, if i force stop the loop the device continue to output the last current.
my question is can i add if condition that turn of the current source?
for example
if force stop
fprintf(device, ':OUTP OFF')
end
 
Physics news on Phys.org
  • #2
liran avraham said:
my question is can i add if condition that turn of the current source?

I'm not a MATLAB expert, but one thing you could try is to place a statement at the very end of the loop that sets a variable to true if the loop completes. Then you could check right after the loop to see if the variable was set to true. If not, then the loop was stopped early.
 
  • #3
that not what i meant.
i asked if there is some way to add a condition to my code that identify a force stop (ctr +c) so when i force stop my current supply output is truned off. in a way some
if (force stop\ctr +c)
turn off device
end

my main loop is endless i built some homemaide temperature controler, i am always measuring tne temperature:
while (1)
...
end
 
  • #4
liran avraham said:
i asked if there is some way to add a condition to my code that identify a force stop (ctr +c)

My mistake. I'm afraid I don't know if that's possible or not, but perhaps someone else here can help you. Good luck!
 

1. Can I add a force stop condition in a loop?

Yes, you can add a force stop condition in a loop. This is a common practice in programming to ensure that the loop stops when a certain condition is met.

2. How do I add a force stop condition in a loop?

To add a force stop condition in a loop, you can use the break keyword in the loop's code block. This will immediately exit the loop when the condition is met.

3. Can I add multiple force stop conditions in a loop?

Yes, you can add multiple force stop conditions in a loop. You can use multiple break statements with different conditions to stop the loop.

4. Is it necessary to add a force stop condition in a loop?

No, it is not necessary to add a force stop condition in a loop. However, it is a good practice to avoid infinite loops and to control the flow of the program.

5. Can I use other keywords instead of "break" to add a force stop condition in a loop?

Yes, you can use other keywords such as return or throw to add a force stop condition in a loop. However, the break keyword is specifically used for this purpose and is the most commonly used in loops.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
3
Views
505
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
570
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • Introductory Physics Homework Help
Replies
1
Views
154
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
Replies
6
Views
978
Replies
9
Views
2K
Replies
9
Views
1K
Back
Top