MATLAB Answers

0

how we write condition in for loop?

Asked by Sanjoy Dey on 3 Apr 2019
Latest activity Edited by Sanjoy Dey on 3 Apr 2019
suppose in c language we have a condition like k=0;k<j;k++
how we write this code in matlab?

  0 Comments

Sign in to comment.

3 Answers

Answer by Raj
on 3 Apr 2019
 Accepted Answer

k=0;
while k<j
k=k+1
end

  0 Comments

Sign in to comment.


Answer by Pruthvi Raj Gampalwar on 3 Apr 2019
Edited by Pruthvi Raj Gampalwar on 3 Apr 2019

Increment of 1
for k = 1:1:j % Increment of 1
% do operations
end
Increment of 2
for k = 1:2:j % Increment of 2
% do operations
end
Decrement from j to 1 in step of 1
for k = j:-1:1 % Decrement of -1
% do operations
end
Please Accept answer if you understood, else ping me for advanced help

  1 Comment

k<j how its work?

Sign in to comment.


Answer by Sanjoy Dey on 3 Apr 2019
Edited by Sanjoy Dey on 3 Apr 2019

i know syntax of for loop--- for index=initial value : step size: final value
but i want to know the condition k<j,how i write this condition?

  0 Comments

Sign in to comment.