1/46
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
function answer = isGreater (n1, n2)
answer = n1 > n2;
end
function area = recArea (width, length)
area = round(width * length, 2);
end
function answer = withTip(bill,tip)
answer = round(bill + (tip * bill),2);
end
function [sumAns, prodAns, meanAns] = allMath(n1,n2,n3)
sumAns = round(n1 + n2 + n3, 2);
prodAns = round(n1 * n2 * n3, 2);
meanAns = round(sumAns/3, 2);
end
function [numMats, costMats] = matMath(w,l, c)
areaMat = w * l;
numMats = round(areaMat, 2);
costMats = round(numMats * c,2);
end
function [needed, leftOver] = theSandbox(w,l,hFt,n)
wFt = w / 12;
lFt = l * 3;
vFt3 = wFt lFt hFt;
total = ceil(vFt3/3);
needed = max(0, total - n);
have = needed + n;
leftOver = round(have * 3 - vFt3, 2);
end
function [score, logical] = raiseMyGrade(Test1, Test2, Test3)
Test4 = 90 * 4 - (Test1 + Test2 + Test3);
score = Test4;
logical = (score <= 100);
end
function answer = isFirstLast (vec)
answer = vec(1) == vec(end);
end
function answer = getLetter(letter)
answer = char('a' + (letter - 1));
end
function answer = calculateTotal(cost,tip)
answer = cost + (cost.*tip/100);
answer = round(answer, 2);
end
function answer = swapBigSmall(vec)
answer = vec;
maxNum = max(vec);
minNum = min(vec);
answer(vec == maxNum) = minNum;
answer(vec == minNum) = maxNum;
end
function answer = deleteMiddleThird(vec)
l = length(vec);
answer = [vec(1:(l/3)), vec(1+(2*l/3):end)];
answer = answer(end: -1 : 1);
end
function answer = hasRepeats(vec)
answer = any(diff(sort(vec)) == 0);
end
A = 'char'
B = 'Whos thE GoAt BUzz'
D = 'Whos the Goat Buzz'
A = Given the string str1 that contains one or more instances of str2, produce a vector of all the starting indices of str2 in str1.
A = strfind(str1, str2)
B = Given the string str3, replace all of the occurrences of str2 in str1 with the string str3.
B = strrep(str1, str2, str3)
C = Capitalize the string str1.
C = upper(str1)
D = Split the string str1 into two parts at the first space. The first part should be everything before the space. Store the first part in D.
E = Store the second part of the string from part D in E, which contains the space and everything afterwards.
[D, E] = strtok(str1, ' ')
F = Find the character that has an ASCII value corresponding to the double num.
F = char(num)
G = Given the double num, create the character vector version of this number.
G = num2str(num)
H = Given the variables name and age, use the sprintf() function to create the sentence:
‘My name is <insert name> and I am <insert age> years old.’
For example, if name is ‘Kantwon’ and age is 31, then the sentence should be: ‘My name is Kantwon and I am 31 years old.’
H = sprintf('My name is %s and I am %i years old.', name, age)
I = Given str1 and str2, produce a logical of whether or not they are the same string (case sensitive).
I = strcmp(str1, str2)
J = Produce a single logical of if str2 is contained within str1
J = contains(str1, str2)
A = Create a mask that is true at all positions of vec1 that contain a number greater than 4
A = vec1 > 4
B = Create a mask that is true at all positions of vec1 that contain an even number
B = mod(vec1, 2) == 0
C = Create a mask that is true at all positions of vec1 that contain an even number that is greater than 4
C = (mod(vec1, 2) == 0) & (vec1 > 4)
D = Produce the quantity of 4’s that are in vec1
D = sum(vec1==4)
E = Create a mask that is true at all positions in str1 that contain a space
E = (str1 == ' ')
F = Create a mask that is true at all positions in str1 that are NOT a space
F = (str1 ~= ' ')
G = Delete all of the spaces in str1 and save this newly modified string in G (it is ok if you do this on multiple lines. Your final string just needs to be saved in the variable G)
G = str1(str1 ~= ' ')
H = Using masking, create a vector of indices of all the locations of capital E’s in str2
H = (1:length(str2)) .* (str2 == 'E')
H = H(H~=0)
mask = double(str2) >= 97 & double(str2) <= 122
I = Using masking, create a vector of all of the lowercase letters in str2
I = str2(mask)
function [n, s] = endCap(vec)
n = length(vec);
s = vec;
s(end) = upper(vec(end));
end
function out = rearrange(vec1, vec2)
[newOrder, originalVec] = sort(vec1);
out = vec2(originalVec);
end
function out = inInterval(lBound, uBound, vec)
out = vec(vec >= lBound & vec <= uBound);
end
function ratio = vowelsToWordRatio(str)
str = lower(str);
vowelsInStr = sum(str == 'a' | str == 'e' | str == 'i' | str == 'o' | str == 'u');
wordsInStr = sum(str == ' ') + 1;
ratio = round(vowelsInStr/wordsInStr, 2);
end
function out = uncensor(str1, str2)
out = str1;
mask = (str1 == '*');
out(mask) = str2(mask);
end
function score = stringScore(str)
len = length(str);
spaces = sum(str == ' ');
score1 = 10 * (spaces > 0 & mod(len,spaces)==0);
capitalized = sum(double(str) >= 65 & double(str)<= 90);
totalLetters = sum(str ~= ' ');
score2 = 7 * (capitalized / totalLetters >= 0.05);
notSpaces = str(str ~= ' ');
capLetters = double(notSpaces) >= 'A' & double(notSpaces) <= 'Z';
lowLetters = double(notSpaces) >= 'a' & double(notSpaces) <= 'z';
negPoint = capLetters(1: end-1) & lowLetters(2:end);
score3 = -sum(negPoint);
low = lower(notSpaces);
revString = low(end: -1: 1);
palindrome = isequal(low, revString);
score4 = 50 * palindrome;
score = score1 + score2 + score3 + score4;
end
function [word, len] = longestWord(str)
spaces = [0, strfind(str,' '), length(str)+1];
lenofWord = diff(spaces) - 1;
[len, indices] = max(lenofWord);
word = str(spaces(indices) + 1 : spaces(indices + 1) - 1);
end
function out = howManyPs(data)
ascii = double(data);
mask = ascii == 80;
out = sum(mask(:));
end
function out = crossoutEvenColumns(data)
[r,c] = size(data);
out = data;
even = 2:2:c;
out(:, even) = 'X';
end
function out = deleteOddRows(data)
[r, ~] = size(data)
odd = 1:2:r;
data(odd,:) = [];
out = data;
end
function [avg, count] = countSalesAboveAvg(sales)
avg = floor(mean(sales(:)));
count = sum(sales(:) > avg);
end
function [totals, sorted] = topGolf(scores, names)
totals = sum(scores, 2);
[totals, idx] = sort(totals, 'ascend');
sorted = names(idx,:);
end
function Outarr = sortTheRows(arr, criteria)
col = str2num(criteria(1));
order = criteria(2);
[~, idx] = sort(arr(:,col));
revIdx = idx(end: -1: 1);
Descending = (order == 'D');
finIdx = idx.*(~Descending)+revIdx.*Descending;
Outarr = arr(finIdx, :);
end
Examples:
temps = [89 80 27 68 73 66 78
92 10 34 14 11 50 72]
[avg, map] = warmerDays(temps)
>> avg = 54.57
>> map = ['HH.HHHH'
'H.....H']
function [avg, map] = warmerDays(temps)
avg = round(mean(temps(:)), 2);
hot = temps > avg;
[r,c] = size(temps);
map = char(46 * ones(r,c));
map(hot) = 'H';
end