In: Computer Science
The following code must be written in Matlab
I want to print the following in Matlab (x1,x2, x3) = (0.33333, 0.33333, 0.33333) . 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 x = (0.33333, 0.33333, 0.33333)
Thanks!
All the explanations is given in the comments of the code itself.
Code--
x = [0.33333, 0.33333, 0.33333];
N=length (x);
%use fprinf to printf
fprintf("(x1,x2,x3) = (");
%iterate over the array and print it
for i=1:N-1
fprintf("%.5f, ",x(i));
end
fprintf("%.5f)",x(i));
----------------------------------------------------------------------------------------------------------------------------------------------------------
Code Screenshot--
----------------------------------------------------------------------------------------------------------------------------------------------------------
Output Screenshot--
----------------------------------------------------------------------------------------------------------------------------------------------------------
Note--
Please upvote if you like the effort.