- fprintf prints to a file or to the command window.
- sprintf prints to a character vector or scalar string.
I'm trying to use fprinft in title because when i use the sprintf function it has way too many decimals. I keep getting error messages and i dont know how to fix them
14 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
subplot (2,2,1)
plot(X,Y)
z2= fprintf('Trajectory of projectile(v0= %2.0f\n and angle %2.0f\n)', v0, theta);
title(z2)
xlabel('Position in X direction (m)')
ylabel('Position in Y direction (m)')
Index exceeds the number of array elements (1).
Error in assigment03_pt01 (line 40)
title(z2)
4 comentarios
Respuestas (1)
Guillaume
el 5 de Feb. de 2020
Editada: Guillaume
el 5 de Feb. de 2020
"I keep getting error messages"
Then read the doc of the functions you use, in particular pay close attention to what the inputs and outputs are.
For this particular error:
Index exceeds the number of array elements (1).
Error in assigment03_pt01 (line 40)
title(z2)
it would be because you have created a variable named title, so title(z2) is no longer passing z2 to the title function but instead is indexing into your title variable.
With regards to sprintf vs fprintf, as Stephen says you can't swap one for the other and in any case they format text exactly the same way (hence the very similar names). You want sprintf. Read the documentation of the format string to customise the display to what you want. Perhaps you want %g instead of %f.
"(i dont know how i made it a variable though)"
Somewhere, you wrote
title = something;
0 comentarios
Ver también
Categorías
Más información sobre Characters and Strings en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!