...
Code Block |
---|
function all_about_me(name, age, study) fprintf("My name is %s",name) fprintf("\n") fprintf("I am %s years old,",age) fprintf(" and I study %s",study) end |
Oppgave 3 - Kodeforståelse
a)
Code Block |
---|
x = 3 y = 2 Funksjonen returnerer hvor mange ganger b går opp i a og resten av divisjon av a på b. |
b)
Code Block |
---|
m = JULENISSEN Funksjonen returnerer en streng med annenhver bokstav hentet fra de to inputstrengene, med første bokstav hentet fra andre inputstreng (y). |
c)
Code Block |
---|
ans = 6 f regner ut den rekursive tverrsummen (av tverrsummen, av ...tallet), helt til det er bare et siffer igjen. |
d)
Code Block |
---|
101011001 Konverterer heltall til binærrepresentasjon |
Oppgave 4
Code Block |
---|
function wordsWithPrefix = checkPrefix(words , prefix) wordsWithPrefix = {}; for i = 1: length(words); iffor word = length(words{i})words >= length(prefix) && strcmp(words{i}(1: length(prefix)) if startsWith(word, prefix) wordsWithPrefix cellArray = [wordsWithPrefix words{i}]; {cellArray, word}; end end end |
Oppgave 5
Code Block |
---|
function isMatch = match(observed , actual) isMatch = true; for pos = 1: length(observed) if (observed(pos) ~= '?' && observed(pos) ~= actual(pos)) isMatch = false; end end end |
Oppgave 6
a)
Code Block |
---|
function date = dateStruct( day , month , year ) date = struct('day', day , 'month', month , 'year', year); end |
b)
Code Block |
---|
function movie = movieStruct(name , director , premiereDate) movie = struct('name', name , 'director ', director , 'premiereDate ', premiereDate '); end |
c)
Code Block |
---|
function validMovies = getMovieStructs(movies , fromYear , toYear) validMovies = []; for movie = movies if movie.premiereDate.year > fromYear && movie.premiereDate.year < toYear validMovies = [validMovies movie]; end end end |
Oppgave 7
Code Block |
---|
function [avgPuls , minPuls , maxPuls] = pulsStatistikk(pulsData) minPuls = inf; maxPuls = -inf; sumPuls = 0; antall = 0; for puls = pulsData antall = antall + 1; if puls < minPuls minPuls = puls; end if puls > maxPuls maxPuls = puls; end sumPuls = sumPuls + puls; end avgPuls = sumPuls/antall; end |
Oppgave Quiz
a)
Code Block |
---|
function result = beginsWith(capitals, letter) result = {}; for city = capitals if city{1}(1)==letter result(end+1) = city; end end end |
b)
Code Block |
---|
function letter = randomLatinLetter(upper) if upper asciiValue = randi([65 90]); else asciiValue = randi([97 122]); end letter = char(asciiValue); end |
...