Write the following commands in the same script file. Leave off the semicolons so all answers print to the command window. Every bulleted instruction should produce some output. Turn in the script and all output.
For the following, you will be getting values out of ts1 and putting them in new variables. All of your commands should be of the form: tsNew = ts1(first:step:last ). Remember that if you leave step out, it defaults to 1 and end is a shortcut for length(ts), ie, the index of the last element. Note, if you’re confused about values versus indices, double click on ts1 in the variable window to bring it up in spread-sheet form. The indices are the numbers along the top (1 2 3), and the values are the ones below that. All of your first:step:last should be indices, not values.
- Get the 3rd element out of ts1 and put it in a variable t3.
- Get the first through third element of ts1 and put the in a variable ts1to3
- Get the 3rd through 1st element of ts1 and put them in a variable ts3to1.
- Get the elements of ts1 in reverse order and put them in a variable tsRev.
- Check that this is correct by printing out the first and last element of tsRev
- Get every other element of ts1 and put it in a variable tsSkip.
- Check that this is correct by printing out the length of tsSkip
- Add one to every element in ts1 and store the result back in ts1. Do this three times. Question: the values in ts1 have changed. Have the values that you created in the previous steps changed? (You can look at them in the variable window).
- Check the new first and last values of ts1
This question belongs to MATLAB software and discusses about application of MATLAB in mathematics to find out the maximum and minimum values in a group of given elements.
Download Full Solution