Matlab Exam 2
What is needed in 01? <01> = 'mountainHeights.txt' ; [ fileID , errorMsg ] = <02> (FILENAME , 'r' ); if <03> > 0 aNum = <04> (fileID, %f, 1); <05> disp (<06>) end
FILENAME
Matlab has a constant "pi" What are the results of sin(pi)?
1.2246e-016
s = 0; sum = 0; while s <= 12 sum = sum + s s = s + 4; end fprintf( ' sum = %.0f \s' , sum)
24
What is the value in aNum? sum = 0; for aNum = [ 1, 3 , 7 ] sum = sum + aNum; end disp (aNum)
7
What is needed in 05? <01> = 'mountainHeights.txt' ; [ fileID , errorMsg ] = <02> (FILENAME , 'r' ); if <03> > 0 aNum = <04> (fileID, %f, 1); <05> disp (<06>) end
else
What is needed in 06? <01> = 'mountainHeights.txt' ; [ fileID , errorMsg ] = <02> (FILENAME , 'r' ); if <03> > 0 aNum = <04> (fileID, %f, 1); <05> disp (<06>) end
errorMsg
What is needed in 03? <01> = 'mountainHeights.txt' ; [ fileID , errorMsg ] = <02> (FILENAME , 'r' ); if <03> > 0 aNum = <04> (fileID, %f, 1); <05> disp (<06>) end
fileID
linspace
first number, last number, how many
What is needed in 02? <01> = 'mountainHeights.txt' ; [ fileID , errorMsg ] = <02> (FILENAME , 'r' ); if <03> > 0 aNum = <04> (fileID, %f, 1); <05> disp (<06>) end
fopen
What is needed in 04? <01> = 'mountainHeights.txt' ; [ fileID , errorMsg ] = <02> (FILENAME , 'r' ); if <03> > 0 aNum = <04> (fileID, %f, 1); <05> disp (<06>) end
fscanf
sprintf vs fprintf
sprintf gets saved in a string and fprintf gets put directly into the command window
x = 0; for n = 1:3 for m = 1:2 myArray(n,m) = x x = x + 5 end end disp (myArray( 2 , 2 ))
0 5 10 *15* 20 25