using non number vectors and number vectors in the same fprintf command (beginner)
Show older comments
hey guys, ive been at this for the past hour something but i can not figure it out, so i thought ill ask it over here. for my homework i need to display output using fprint f with some borders, but its proving beyond my problem solving abilities.
so i have this code
x=[9 4 0 7];
x2=1./x;
x3=myFactorial(x);
x4=factorial(x);
fprintf('%15.4f %15.4f %15.4f %15.4f\n', x',x2',x3',x4')
which is all good (dont worry about x3 its just from a previous q), but i need to add a border like this :----------- to the top.
the closest ive come is with the command fprintf('--------------------\n %15.4f %15.4f %15.4f %15.4f\n', x',x2',x3',x4'), which gives off a weird
--------------------
9.0000 4.0000 0.0000 7.0000
--------------------
0.1111 0.2500 Inf 0.1429
--------------------
362880.0000 24.0000 0.0000 5040.0000
--------------------
362880.0000 24.0000 1.0000 5040.0000
without the \n after the ---- it does the same thing but with the numbers on the same level as the ---- in the output. ive tried many things like putting the ----- phrase in a vector and then putting the vector in the fprint command, but that simply gives me no output. question is how can i get something like this
--------------------------------------------------------------------------------
9.0000 4.0000 0.0000 7.0000
0.1111 0.2500 Inf 0.1429
362880.0000 24.0000 0.0000 5040.0000
362880.0000 24.0000 1.0000 5040.0000
in only one fprintf command line.
Sorry if its a beginner question but ive searched many forums and didnt find anyone else having the same problem, as it can be simply solved by multiple fprintf command but i have my limitations in the actualy question.
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!