using input form from user, use for and while loops for the number in matlab

To use input from the user and loops in MATLAB, you can follow the code snippet below:

main.m
% Ask user for input
n = input('Enter a number: ');

% Using for loop
for i = 1:n
   disp(i);
end

% Using while loop
i=1;
while i<=n
   disp(i);
   i = i + 1;
end
164 chars
15 lines

In the code above, we first ask the user to input a number and store it in the variable "n". We then use a for loop to display the numbers from 1 to n and a while loop to do the same thing. The while loop continues to run until the value of "i" is no longer less than or equal to "n".

You can modify the code above to suit your specific use case.

gistlibby LogSnag