How to get the last variable of a for loop in MATLAB

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 2K views
KonaGorrila
Messages
12
Reaction score
0
Aloha guys,

I am just having trouble getting MatLab to output only the last variable of my "for loop."
If anyone can help all I am looking for is an example of notation.
p.s. I have done this before just not in a while and will continue to look through my old scripts and functions. just not in a while.
Thank you,
HWN Phisics Nerd :P
 
Physics news on Phys.org
KonaGorrila said:
Aloha guys,

I am just having trouble getting MatLab to output only the last variable of my "for loop."
If anyone can help all I am looking for is an example of notation.
p.s. I have done this before just not in a while and will continue to look through my old scripts and functions. just not in a while.
Do you mean the last value of your loop control variable?

If so, here's how you would do it in C, which should be fairly close to what it would be in matlab.

C:
int N = 10;
int i;

for (i = 0; i < N + 1; i++)
{
   if ( i == N) printf("Last value is %d", i);
}