What does (%f\n) mean in MATLAB?

91 Views Asked by At

There's this example that was shown in our class today:

age = 20
fprintf("age is"%f\n);

What is the purpose of "%f\n"? I initially thought it was a placeholder for variables.

It should come out as

age is 20

in the output bar.

If we are using the variable age, how can I rewrite this program?

1

There are 1 best solutions below

0
James Tursa On

The %f is indeed a placeholder for variable output in MATLAB, but this syntax is invalid:

age = 20 fprintf("age is"%f\n);

What it should be is:

age = 20;
fprintf("age is %f\n",age);

The \n part is a newline to advance the cursor to the next line.