{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

prob2 HW2

# prob2 HW2 - (b Find the 1st 2nd 3rd 5th and 8th numbers in...

This preview shows page 1. Sign up to view the full content.

% Script Name: prob2 % Script Variables: % 1. vOdd (double) - a vector with every odd-indexed number from vec % 2. vFib (double) - the 1st, 2nd, 3rd, 5th, and 8th number from vec % 3. vBig (double) - a vector with all of the numbers greater than 5 from % vec % 4. vSmall (double) - a vector with all numbers less than the mean of % vec % % Problem Statement: % You are given a vector "vec", defined as: % vec = [43 8 1 6 83 53 44 -11 90];. % Using the given "prob2" script, create the following vectors. All of % the following vectors are subsets of the original vector vec, so you % should create them by indexing numerically or logically. Do not use % direct entry for your answers. % % (a) Find every other number in vec, starting with the first number. % Store your answer in the variable "vOdd" (in other words, you are % finding all of the numbers that have odd indices).
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: % % (b) Find the 1st, 2nd, 3rd, 5th, and 8th numbers in vec. Store your % answer in the variable "vFib". % % (c) Find all numbers in vec that are greater than 5. Store your % answer in the variable "vBig". % % (d) Find all numbers in vec that are less than the average (mean) of % the vector vec. Store your answer in the variable "vSmall". vec = [43 8 1 6 83 53 44 -11 90]; % DO NOT CHANGE THIS LINE % calculation of vOdd using colon operator vOdd = vec(1:2:end); % calculation of vFib using colon operator and some manual indexing vFib = vec([1:1:3 5 8]); % calculation of vBig using boolean indexing and max function of matlab vBig = vec(vec > 5); % calculation of vSmall using boolean indexing and min function of matlab % and the mean function of matlab vSmall = vec(vec < mean(vec));...
View Full Document

{[ snackBarMessage ]}