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

  • #1
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
 

Answers and Replies

  • #2
34,272
5,910
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);
}
 

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

  • Last Post
Replies
3
Views
3K
Replies
4
Views
8K
Replies
3
Views
8K
Replies
1
Views
3K
  • Last Post
Replies
3
Views
787
  • Last Post
Replies
10
Views
16K
  • Last Post
Replies
5
Views
3K
  • Last Post
Replies
1
Views
627
  • Last Post
Replies
3
Views
3K
Top