clc clear all % use of vectors % be sure to use element notation disp('Some examples of vectors in use') %% Example 1 - Display grades disp('Example 1') disp(' Display grades in two columns') disp(' ') % input - vector of grades, grade grade=[70 85 63 100 97]; % quiz grades amount=length(grade); % determine number of grades disp(' Quiz number and grade:') for i=1:1:amount fprintf(' Quiz #%g - %g\n',i,grade(i)) end disp(' ') disp(' ') %% Example 2 - Generate a desired vector disp('Example 2') disp(' Generate a vector of alternating 0 1 0 1... elements') disp(' ') % input - length of desired vector elements=8; fprintf(' The desired vector length is %g\n',elements) for j=1:1:elements if (-1)^j==(-1) vector(j)=0; end if (-1)^j==1 vector(j)=1; end end disp(' The output vector is:') disp(vector) disp(' ') %% Exercise 1 - Chapter 26 % Finding the min and max numeric values in a vector disp('Exercise 1 - Chapter 26') disp('Find the min and max elements contained in any vector') % inputs vec=[12 9 -10 8 8.9 -7.8 15]; disp(' The input vector is:') disp(vec) % CODE % assume the first element is the min or max maxv=vec(1); minv=vec(1); % find number of elements n=length(vec); for i=2:1:n if vec(i)>maxv maxv=vec(i); end if vec(i)