How to compute Factorial n using simple Stateflow Chart and recursive MATLAB Function?

In this video it shows how the factorial of an input number n can be computed in MATLAB function and Stateflow chart. Main objective of this video is to show how simple and easy it is to design a stateflow chart to calculate the factorial of a number. To explain this in the initial part, this video shows how the factorial can be computed using in-built factorial function, for loop or recursive matlab function. Towards the later part it shows the steps to design a stateflow chart for the factorial.

We will be glad to hear from you regarding any query, suggestions or appreciations at:

Source code:

function outputArg = Factorial_MATLAB(inputArg)

% outputArg = factorial(inputArg);

% outputArg = 1;

% for i=inputArg:-1:1
% outputArg = outputArg*i;
% end

%% Recursive function

if inputArg<=2
outputArg = 2;

outputArg = inputArg * Factorial_MATLAB(inputArg-1);

Leave a Reply