{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

ABCs_vectors - located(F[E F]=min(vec Sort the vector vec...

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

View Full Document Right Arrow Icon
function [A B C D E F G H I J K L] = ABCs_vectors(n, vec, vec2) f % Create a vector, A, that consists of n equally spaced numbers between 1 % and 2. Use linspace. A = linspace(1,2,n); A % Create a vector, B, that goes from 12 to n in steps of 4. Use the % colon operator. B=12:4:n; % Create a vector, C, consisting of n 391s. ([391 391 391...]). Use the % zeros or ones function. C=391.*ones(1,n); % vec is a vector with at least 5 elements (numbers). Find the following % and store them in the indicated variables. % Example. Find the second element of vec (Z). Z = vec(2); Z % Find the number of elements in the vector vec (D). D=length(vec); % Find the smallest element in vec (E), and the index at which it is
Image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: % located (F). [E F]=min(vec); [ % Sort the vector vec and store it in (G). G=sort(vec); % vec2 is also a vector. Concatenate vec and vec2 in that order (H). H=[vec vec2]; % Reverse vec2 and store the resulting vector in (I). I=fliplr(vec2); % Find the last element of vec2 (J). Do it without using the length % function. J=vec2(end); % Starting with the first element, find every other element in vec2. That % is, find every element in vec2 that occurs at an odd-numbered index (K). K=vec2(1:2:length(vec2)); % Find all of the numbers in vec2 that are less than 5. (L) L=vec2(vec2<5);...
View Full Document

{[ snackBarMessage ]}