Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Matlab fprintf help This is the question: I have already done part a, I need hel

ID: 3876275 • Letter: M

Question

Matlab fprintf help

This is the question:

I have already done part a, I need help with part b.

This is my current code:

% array of Pounds to convert to Kilograms

weight_pound = [50.543 65.676 75.343 80.937]

% for Loop that calls from the array weight_pounds

for index=1:4

%Convert weight from Pounds to Kilograms

    weight_kg = weight_pound*0.453592

%Print out the conversion

% ‘%5.2f’ for 2 decimals for Kilograms

% ’%5.0f’ for no decimals in pounds

    fprintf(‘%5.2f kg = %5.0f lb ',weight_pound(index),weight_kg);

% end loop

end

Matlab isnt accepting my code. It says its full of errors. Help!

In Problem 5, the conversion to go from pounds to kg was given as In this expression, we note that the conversion factor, 0.453592, has six digits after the decimal point. Depending on the application, when displaying the converted weight, we may or may not want to display that many digits. a) using the fprintf statement and the % f conversion specification, create a MATLAB script that displays the weight in kg with exactly 3 digits after the decimal point. For example if the weight in pounds is 150, then the weight in kg should be displayed as Weight = 68.039 kg ote our Erriats statement should be in terms of a variable, not only constants. Paste your code here: weight pound-150 % Convert Pounds to Kilograms weight-kg. = weight_aound*0.453592 % Print the weight in Kilograms terintt('weight = %5.3f kg, weight-kg)

Explanation / Answer

I found 2 erros in the code you wrote

Output

50.5 kg = 111 lb
65.7 kg = 145 lb
75.3 kg = 166 lb
80.9 kg = 178 lb

I found 2 erros in the code you wrote

  • 1 kg = 2.20462 lbs
  • You were trying to do weight_pound*2.20462 but it should be weight_pound(index)*2.20462 because you need one element at a time
weight_pound = [50.543 65.676 75.343 80.937];
for index=1:4
weight_kg = weight_pound(index)*2.20462;
fprintf('%5.1f kg = %5.0f lb ',weight_pound(index),weight_kg);
end

Output

50.5 kg = 111 lb
65.7 kg = 145 lb
75.3 kg = 166 lb
80.9 kg = 178 lb