0
0
9
0
0
0
0
4
0
0
0
0
yr(k)<=4
&&
greek(k)
binNum= maj(k);
data(binNum) = data(binNum) + 1;
end
end
bar(1:75, data)
title(Number of undergrads in each major who participate in Greek life)
xlabel(Major code);
ylabel(Count)
a = [s m a r t]
THIS ONE-->
b = smart
c = {s mart}
THIS ONE-->
d = [c{1} c{2}]
e = {c{1} c{2}}
f = {b }
(b) The script below reads a plain text file. Add code to the script to determine and print the number
of lines in the file that begin with the string DATA. Assume that the text file myData.txt is accessible
and not empty. Do not modify or cross out the given statements and do not use built-in functions find
or strfind.
% Read a text file
fid = fopen(myData.txt,r);
n = 0;
while ~feof(fid)
s = fgetl(fid);
if
end
disp(n)
fclose(fid);
[a,b] = size(m);
[nrp, ncp, nlp] = size(P);
Example solution:
nr= nrp/a;
nc= ncp/b;
for i= 1:a
for j= 1:b
% block ij
blk= P( (i-1)*nr+1 : i*nr,
(j-1)*nc+1 : j*nc ,
ind= m(i,j);
Q( (ind-1)*nr+1 : ind*nr , 1:nc , : )= blk;
end
end
: );
function g = darkerGray(Z, a, b, i, j)
% Z is a 3-d uint8 image array.
% Calculate the gray values of pixels (a,b) and (i,j) of array Z and assign
% to g the darker of the two gray values. g is a type uint8 scalar.
% Calculate the gray value as the arithmetic mean of the red, green, and
% blue values. Assume that a, b, i, and j are valid indices in array Z.
% ONLY these functions are allowed (although you may not need them): uint8, double.
Example solution:
gab= Z(a,b,1)/3 + Z(a,b,2)/3 + Z(a,b,3)/3;
gij= Z(i,j,1)/3 + Z(i,j,2)/3 + Z(i,j,3)/3;
if gab < gij
g= gab;
else
g= gij;
end
nPeople= length(S);
for i = 1 : nPeople-2
% going all the way to n is OK
for j = i+1 : nPeople-1 % going all the way to n is OK
for k = j+1 : nPeople
if (~strcmp(S(i).col, S(j).col) || ...
~strcmp(S(j).col, S(k).col) || ...
~strcmp(S(i).col, S(k).col) ) && ...
S(i).sem + S(j).sem + S(k).sem == 10
n = n + 1;
T(n,1)= S(i);
T(n,2)= S(j);
T(n,3)= S(k);
end
end
end
end
if n==0
T= [];
end
for r= 1:nr
% Check the string in M(r,:)
nFound= 0; % number of matches with p found so far
c= 1;
while c<=nc-np+1 && nFound<3 % more efficient to use while than for
if strcmp(p, M(r,c:c+np-1))
nFound= nFound + 1;
end
c= c+1;
end
if nFound==3
k= k+1;
Z{k}= M(r, 1:(c-1)+np-1);
end
end
if k==0
Z= {};
end