Q:

Create a vector variable vec; it can have any length. Then, write assignment statements that would store the first half of the vector in one variable and the second half in another

0

 Create a vector variable vec; it can have any length. Then, write assignment statements that would store the first half of the vector in one variable and the second half in another. Make sure that your assignment statements are general, and work whether vec has an even or odd number of elements (Hint: use a rounding function such as fix). 

All Answers

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

>> vec = 1:9;

>> fhalf = vec(1:fix(length(vec)/2))

fhalf =

 1 2 3 4

>> shalf = vec(fix(length(vec)/2)+1:end)

shalf =

 5 6 7 8 9

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