How to use fprintf properly?
Mostrar comentarios más antiguos
Here is the question:
Write a script that does the following. Use fprintf and do not show scientific notaiton. NOTE: You will be able to reuse this code in Project 2. Publish your results from MATLAB in a Word document and upload here.
- Generate an array y with 100 elements that is normally distributed with a mean of 2.5 and a standard deviation of 1 using the expression 2.5+1*randn(1). Notice you will get fractional results.
- Determine the average y-value (use fprintf and avoid scientific notation). Use a for loop (do not simply use the command mean().)
- Determine the number of y-values less than the number 2.0
PLEASE DO NOT GIVE ME THE COMPLETE ANSWER TO THIS WHOLE PROBLEM. I just want to know if I should split this question into three different sections using "%%" or if I should just lump the whole thing together. Also, I am trying to use fprintf and am having very little success. Do I put fprintf in three separate sections or just at the end of the whole problem? Thanks!
Respuesta aceptada
Más respuestas (1)
Tony Dimichele
el 9 de En. de 2020
y = 2.5+1*randn(100,1)
histogram(y)
will produce a normally distributed histogram looking like.

fprintf('Hey') in the command line produces what for you?
fprintf('%.2f', y(1)) produces what for you?
If you use a for loop to find the mean, and name a variable after the value found, you can display the mean in the command window with an fprintf statement like above
Categorías
Más información sobre Data Type Conversion en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!