The following code must be written in Matlab
I want to print the following in Matlab (x1,x2, x3, ....xn) = (0.33333, 0.33333, 0.33333,....) That is for n variables . The whole thing should be on the same line.
I need to use fprintf and write out the coordinates with 5 decimal places of variable xn = (0.33333, 0.33333, 0.33333,....)
Thanks!
I have provided the solution according to the problem statement, if you have any problem ask in the comments, i will help you.
Copy and Paste code:
function printInOneLine(n)
X = ones(1,n)*0.333333;
fprintf("%.5f",X); %.5f is used to set the precision to 5 decimal places
end
Output:
printInOneLine(15)
0.333330.333330.333330.333330.333330.333330.333330.333330.333330.333330.333330.333330.333330.333330.33333
Get Answers For Free
Most questions answered within 1 hours.