TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

Matlab

For Loop Example in MATLAB

Introduction

For loop is an iterative loop in MATLAB. It is used to repeat and execute a set of instructions over and over for predefined number of times. Loop variable is used to track the current iteration. In simple terms, we can use the for loop in the MATLAB scripts/function if we know the number of iterations.

for loop syntax

for loopVariable =  loopStart:loopEnd

loop statements   % Iterative loop statements

end

Sample Script

% MATLAB For loop Demo Script.
% www.TestingDocs.com

clc;
clear;

fprintf("This loop runs for 10 times \n");
for i = 1:10
 fprintf("Loop variable value : %d \n", i);
end

–

Script Output

This loop runs for 10 times
Loop variable value : 1
Loop variable value : 2
Loop variable value : 3
Loop variable value : 4
Loop variable value : 5
Loop variable value : 6
Loop variable value : 7
Loop variable value : 8
Loop variable value : 9
Loop variable value : 10

 

MATLAB For Loop Script

Related Posts

Matlab /

Taylor series expansion MATLAB Example

plot command MATALB

Matlab /

MATLAB 2D Plot command

Pie Chart Demo Matlab

Matlab /

Pie Chart Example using MATLAB

New Function

Matlab /

Functions in MATLAB

MATLAB Command Window

Matlab /

MATLAB Command Window

‹ MATLAB 2D Plot command› Taylor series expansion MATLAB Example

Recent Posts

  • MS Access Data Types
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version