how do these function (separate functions)
    4 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
clc; clear;
input=['MATLAB'];
for i= 1:length(input)
    fprintf(input(1:i))
    fprintf('\n')
end
%-----------------------------------------------------------------------------------------
clc; clear;
for j=length(input):-1:2
    fprintf(input(1:j-1))
    fprintf('\n')
end
for x= 5:-1:1
    msg=[];
    for y = 1 : x
        number= x*y;
        msg = [msg number];
    end
    disp(msg);
end
%-----------------------------------------------------------------------------------------
clc; clear;
height = 10;
for i= 1:height;
for j= i:height;
        if mod(i,2)==0
            fprintf 'O'
        else
            fprintf 'X'
        end
    end
        fprintf '\n'
end
0 Commenti
Risposte (1)
  Avni Agrawal
      
 il 19 Giu 2024
        I understand that you are trying to define all the functions in one file using local functions in MATLAB. Here is how you can organize all three functions into a single script file. Note that only the main function or script code can directly call these local functions; they are not accessible from outside this file.
% Main script section (if needed)
clc; clear;
inputStr = 'MATLAB';
printChars(inputStr);
displayMultiplications();
printPattern(10);
% Local functions below
function printChars(input)
    for i= 1:length(input)
        fprintf(input(1:i))
        fprintf('\n')
    end
    for j=length(input):-1:2
        fprintf(input(1:j-1))
        fprintf('\n')
    end
end
function displayMultiplications()
    for x= 5:-1:1
        msg=[];
        for y = 1 : x
            number= x*y;
            msg = [msg number];
        end
        disp(msg);
    end
end
function printPattern(height)
    for i= 1:height
        for j= i:height
            if mod(i,2)==0
                fprintf('O')
            else
                fprintf('X')
            end
        end
        fprintf('\n')
    end
end
I hope this helps!
0 Commenti
Vedere anche
Categorie
				Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

