MATLAB: (simple) problem for function that doesn’t return value

functionprintreturnvalue

Hello, i am very new to MATLAB and have stumbled upon something (hopefully extremely simple) that i cannot seem to understand.
I am simply trying to make a function that prints the entered values of a vector entered in the function. It results in a = a, a = b and a = c. The b and c in the second and third prints are completely ignored.
function p62(a,b,c)
fprintf('a = %.1f\n',a)
fprintf('b = %.1f\n',b)
fprintf('c = %.1f\n',c)
end
I tried to replace a, b and c (not in the function but in the prints) with p62(1), p62(2) and p62(3), but it only accepts p62(1) and gives error for p62(2) and p62(3). I hope you understand!

Best Answer

It works fine for me. Here is test2.m:
function test2
clc; % Clear the command window.
p62(10,200, 300); % Call the function
function p62(a,b,c)
fprintf('a = %.1f\n',a)
fprintf('b = %.1f\n',b)
fprintf('c = %.1f\n',c)
I put both functions into the same file, but you don't have to. And here is what it reports to the command window:
a = 10.0
b = 200.0
c = 300.0
What did you do differently?