Q:

Write a for loop that will print the elements from a vector variable in sentence format, regardless of the length of the vector. For example, if this is the vector:

0

 Write a for loop that will print the elements from a vector variable 

in sentence format, regardless of the length of the vector. For 

example, if this is the vector:

>> vec = [5.5 11 3.45];

this would be the result:

Element 1 is 5.50.

Element 2 is 11.00.

Element 3 is 3.45.

The for loop should work regardless of how many elements are in the 

vector.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

>> vec = [44 11 2 9 6];

>> for i = 1:length(vec)

 fprintf('Element %d is %.2f\n',i,vec(i))

 end

Element 1 is 44.00

Element 2 is 11.00

Element 3 is 2.00

Element 4 is 9.00

Element 5 is 6.00

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now