I am writing a function in MATLAB and need to put a variable range of numbers in an fprintf. I need it to start at 1 and go to the length of a matrix. However what I think should work is not giving me consecutive numbers.
A=[1 2 3; 4 5 6; 7 8 9]
b=[2;4;6]
d=length(A)
k=1:d
Then I insert my function for the answer I want, p.
fprintf(‘The solution is x%i equals %f \n’, k, p)
In the output response it’s not giving me the correct k value which should be “1” “2” or “3”. The answer itself is correct if I leave the “x%i equals” out.
ETA: Right now I’m getting:
The solution is x1 equals 2.0000
The solution is x3 equals -0.6667
The solution is x1.333333e+00 equsls 0.000
If I leave out the x%i, I get:
The solution is -0.6667
The solution is 1.3333
The solution is 0.0000