Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

MATLAB Functions and Operators, Exams of Computer Programming

An extensive list of matlab functions and operators, including their definitions, examples, and usage. It covers various categories such as arithmetic, logical, matrix, string, and more. This resource is useful for students and professionals working with matlab for data analysis, programming, and mathematical computations.

Typology: Exams

2023/2024

Available from 05/29/2024

wilfred-mburu
wilfred-mburu 🇬🇧

358 documents

1 / 13

Toggle sidebar

Related documents


Partial preview of the text

Download MATLAB Functions and Operators and more Exams Computer Programming in PDF only on Docsity! MATLAB BASIC PROGRAMMING. QUESTIONS & ANSWERS. ALREADY GRADED A+. - myArray( [3, 4, 5] ) yields the new row array [70, 80, 90]. The indexing array is the integer array [3, 4, 5]. -myArray( [3:1:5] ) also yields [70, 80, 90]. The double colon operator can be used to construct the indexing array. -myArray(3:1:5) yields the same. When constructing a row array using the double colon operator, the brackets are optional. Omitting the brackets in an assignment statement, as in myArray = 50:10:90, is discouraged. In contrast, omitting the brackets for the indexing array is commonplace. -myArray(3:5) yields the same. The default increment of 1 in the double colon operator is commonly used when indexing. - ANSFor example, if myArray = [50, 60, 70, 80, 90], then: ' (transpose operator) - ANSmakes [1,2,3,4] into [ 1 2 3 4 ] 's' - ANSComplete the statement to obtain a string from the user rather than a number. userName = input('Sally',_____); " - ANSTwo single quotation marks print a single quotation mark. Note that a single quotation mark alone would instead indicate the end of the format specification. ( ) parenthesis ~ not & and | or left-to-right - ANSlogical operators order of operation [0, 0, 1] & is applied element-wise, yielding [1 & 0, 0 & 0, 1 & 1] = [0, 0, 1] - ANS[1, 0, 1] & [0, 0, 1] yields what new array? [1, 1, 1, 0] - ANS~[0, 0, 0, 1] yields what new array? [3,5;2,4;1,9] - ANSWhat is matrixC after executing the following statement? matrixA = [ 3, 1, 4; 2, 5, 9 ]; matrixC = reshape( matrixA, 3, 2 ) \\ - ANSTwo backslash characters print one backslash character. Note that a single backslash character would instead indicate the start of a special character sequence like \n. \n - ANSprints a new line \t - ANSprints a tab & - ANSboolean & %-8.2f - ANSFixed-point occupying a minimum of 8 digits, left-aligned, with 2 digits to the right of the decimal point. %.4f - ANSFixed-point with 4 digits to the right of the decimal point. %% - ANSTwo percent characters print one percent character. Note that a single % character would instead indicate the start of a formatting operator like %f. %c - ANScharacter %d - ANSinteger %e - ANSscientific notation %E - ANSscientific notation %f - ANSfixed-point %G - ANSeither %f or %E whichever is shorter %g - ANSwither %f or %e whatever is shorter %i - ANSinteger %s - ANSstring | - ANSboolean or ~a or not(a) - ANSNot negates or complements the value of a, returning true if a is false, and vice versa. 0 count(stringIn, patternSeek) - ANSreturns the number of occurrences of string scalar patternSeek in the string scalar stringIn. count(stringIn, patternSeek, 'IgnoreCase', true) ignores case when counting the number of occurrences of pattern. csc - ANScosecant ctrl-c - ANSWhile not a MATLAB command, this keystroke sequence interrupts an endless MATLAB calculation that a programmer may have entered accidentally. Afterwards, the programmer can enter a new command. diag([vector]) - ANSreturns a square array with the values in the 1D array argument vector on the diagonal and zeros elsewhere diary - ANSRecords into a file almost everything that appears in the command window. The file's name is chosen by programmer, such as "my session.txt". "diary off" ends the recording dis(distance); - ANSOutput the value of a variable named distance. double colon operator - ANSconstructs a numeric row array by specifying a starting value, an increment value, and a terminating value, with those values separated by colons. Ex: myArray = [5:1:9] yields array [5, 6, 7, 8, 9]. endsWith(String1,TestPattern) - ANSperforms case-sensitive logical comparison returning 1 (true) if scalar array string1 end with the specified testPattern, and returns 0 (false) otherwise. If testPattern is a string array containing multiple patterns, then endsWith returns 1 if string1 ends with any element of testPattern. endWith(string1, testPattern, 'IgnoreCase', true) ignores case when determining if string1 ends with testPattern. exit - ANSexits the MATLAB session exp - ANSexponential eye - ANSreturns an m by n array aEye with ones on the main diagonal and zeros elsewhere. figure(n) - ANSmakes figure number n the current figure find(inputAr) - ANS______ locates all nonzero elements of inputAr and returns the linear indices of these elements in outLin. If inputAr is a row array, then outLin is a row array; otherwise, outLin is a column array. If the values of the array elements are needed, the statement inputAr(outLin) is used. find(matrixA(:,1) == 2) - ANSIdentify by number the rows in the 2D array matrixA that start with 2. Use the find function. fliplr(A) - ANSflips array left to right flipud(A) - ANSflips array upside down Floating point number - ANSMATLAB stores a real number as a _______. function attendanceValues = ShiftValues(attendanceValues) % Change indexing values attendanceValues(1:3) = attendanceValues(2:1:4); end - ANSWrite a *single* statement that shifts row array attendanceValues one position to the left. The rightmost element in shiftedValues also keeps its value. Ex: [10, 20, 30 40] after shifting becomes [20, 30, 40, 40]. gtext - ANSallows positioning of text with the mouse hold off - ANSreleases hold on current plot and allows a new graph to be drawn hold on - ANSallows multiple plots to be superimposed on the same axes i - ANSimaginary unit equal to sqrt(-1) identifier - ANSA variable's name is called an ______. Inf - ANSInfinity input - ANSWhat function obtains a number from a user? input('Enter your age:') - ANSComplete the statement that prompts the user with 'Enter your age: ' and assigns the variable userAge with the user-entered value. UserAge = ___________ integer number - ANSpositive or negative number that does not have a fractional part interpreter - ANSwill directly read a high-level statement written in the programming language, execute the operation specified by that statement, then read the next statement, and so on. is keyword(stringin) - ANSreturns a single logical true (1) value if the string stringIn is a keyword in the MATLAB language and logical false (0) otherwise. is the minimum field width that will be displayed - ANSfieldWidth __________ isa(obj,ClassName) - ANSdetermines whether input obj is an object of specified class ClassName. ischar - ANSdetermines whether a variable is a string ischar(charVecIn) - ANSreturns a single logical true (1) value if the input charVecIn is a character array, returning logical false (0) otherwise. ischar(inArray) - ANStests for character vector. iscolumn(inArray) - ANStests for column 1D arrays. isempty(inArray) - ANStests whether inArray is empty. isequal(inArray1,inArray2,....,inArrayN) - ANStests whether input arrays inArray1, inArray2, through inArrayN have the same contents (i.e., whether each array element at each index is equal).All NaN (not a number) values are considered to be NOT equal to each other. isequaln(inArray1,inArray2,....,inArrayN) - ANStests whether input arrays inArray1, inArray2, through inArrayN have the same contents (i.e., whether each array element at each index is equal). All NaN (not a number) values are considered to be equal to each other. isfinite(inArray) - ANSreturns a logical array finiteArray, of the same size as inArray. The value at finiteArray(index) is true when inArray(index) is finite. Otherwise, the values are false. isfinite(x) - ANSReturns true if x is finite; otherwise, returns false. For example, isfinite(Inf) is false, and isfinite(10) is true. isfloat(inArray) - ANStests for floating-point array. isinf(inArray) - ANSreturns a logical array infiniteArray, of the same size as inArray. The value at infiniteArray(index) is true when inArray(index) is infinite. Otherwise, the values are false. isinf(x) - ANSReturns true if x is +Inf or -Inf; otherwise, returns false. isinteger(inArray) - ANStests for integer array. isletter - ANSReturns the indices of all the alphabetic characters in a string. isletter(charVecIn) - ANSfinds all alphabetic letters in the character vector charVecIn. Returns an array the same size as charArrayIn containing logical true (1) at indices pi - ANSThe ratio of a circle's circumference to its diameter, about 3.1415... plot - ANSline plot plotyy - ANSLine plots with y axes on both the left and right side real number - ANSpositive or negative number that may have a factional part realmax - ANSLargest floating point number realmin - ANSsmallest floating point number repmat(A,B,C) - ANSThe function _________ creates a large array by replicating (tiling) a smaller array. arrayOut consists of an mRow-by-nCol tiling of copies of subarrayIn. reshape (arrayIn,numRow,numCol) - ANSThe function _______ returns array reshapeOut with dimensions numRow × numCols. The elements of reshapeOut are taken column-wise from the input array argument arrayIn. rot90(A) - ANSRotates array by 90 degrees counter clockwise around element at index (1,1) save dataY y - ANSSuppose the workspace consists of only two variables x = [3, -1, 4] and y = 98.6. Write a command on the command line that only saves the variable y to the file dataY. Do not include the .mat extension. script - ANSa sequence of statements stored in a text file. MATLAB® requires that the name of a script file must end in .m, in order to be executable by the MATLAB interpreter. sec - ANSsecant semilogx - ANSLine plot with logarithmic x and linear y axes semilogy - ANSLine plot with linear x and logarithmic y axes signed 32-bit integer - ANSint32 signed 8-bit integer - ANSint8 signed integer - ANSrepresents both positive and negative integer values sin - ANSSine sind - ANSSine of argument in degrees sinh - ANShyperbolic sine size - ANSrow x column size( ) - ANSreturns the number of rows and number of columns (nRow, nCol) of the array inArray. If only the row dimension is needed, then the programmer should use size(inArray,1). If only the column dimension is needed, then the programmer should use size(inArray,2). size(inputArray) - ANSreturns the size of each dimension of inputArray sort(inArray) - ANSsorts the elements of inArray in ascending order and returns the result in sortOut. For 2D arrays, sort(inArray) sorts each column of inArray in ascending order. To achieve descending order, the function call is sort(inArray,'descend'). sortrows(inArray,colRef) - ANSsorts the array inArray based on the values in column colRef while keeping the rows together. For any rows that have equal elements in a particular column, sorting is based on the column immediately to the right. sprintf(formatSpec,arrayIn1,...,arrayInN) - ANSformats the data in arrays arrayIn1, ..., arrayInN according to the formatSpec, a string scalar, in column order, and returns the results to string scalar stringOut. The sprintf function returns only a string scalar (if the formatSpec is a string scalar) or a character vector (if the formatSpec is a character vector). sqrt - ANSsquare root stairs - ANSstair step graph startsWith(String1, TestPattern) - ANSperforms case-sensitive logical comparison returning 1 (true) if scalar array string1 starts with the specified testPattern, and returns 0 (false) otherwise. If testPattern is a string array containing multiple patterns, then startsWith returns 1 if string1 starts with any element of testPattern. startsWith(string1, testPattern, 'IgnoreCase', true) ignores case when determining if string1 starts with testPattern. strcmp(string1, string2) - ANSperforms case-sensitive comparison between two strings for equality. If the strings are equal, they must have the same content and length. The input arguments can be any combination of string arrays, character vectors, and cell arrays of character vectors. strcmpi(string1,string2) - ANSperforms case-insensitive comparison between string1 and string2 for equality. If the strings are equal, they must have the same content (independent of case) and length. The input arguments string1 and string2 can be any combination of string arrays, character vectors, and cell arrays of character vectors. strength(stringln) - ANSreturns the number of characters in each element of the input string array. The size of number is the same as the size of stringIn. strfind(stringIn,pattern) - ANSsearches the string stringIn for occurrences of a shorter string or pattern, and returns the starting index of each such occurrence in the numeric array startIdxArray. If a pattern is not found in stringIn, or if the pattern is longer than stringIn, then strfind returns the empty array []. If stringIn is a string scalar, or a character vector, then strfind returns a vector of type double. If stringIn is a string array or cell array of character vectors, then strfind returns a cell array of vectors of type double. string(inputArray) - ANSconverts the input array inputArray to a string array stringOut. If inputArray is a character vector, then string() converts inputArray to a string scalar. If inputArray is a numeric array, then string() converts each number to a string element in stringOut. If inputArray is a cell array or a categorical array, then string() converts each element in inputArray to a string element in stringOut. In contrast to the char function, string() does not treat numbers as UTF-16 codes. If inputArray is a logical array, then string() converts each value to either "false" or "true". If inputArray is [], then string returns a 0-by-0 string array. strings(n,m) - ANSreturns an n-by-m array of strings with no characters stringArray = strings(sz) returns an array of strings with no characters, where size vector sz defines size(str). strjust - ANSReturns a center-justified string. strncmp(string1,string2) - ANSperforms case-sensitive comparison of the first n characters between string1 and string2 for equality. The input arguments string1 and string2 can be any combination of string arrays, character vectors, and cell arrays of character vectors. strncmpi(string1,string2) - ANSperforms case-insensitive comparison of the first n characters between between string1 and string2 for equality. The input arguments string1 and string2 can be any combination of string arrays, character vectors, and cell arrays of character vectors. strrep - ANSFinds a substring within a string and replaces with a different string. subplot - ANScreates vertically stacked plots subplot(a,b,c) - ANScreates an a x b matrix of plots with c the current figure switch statement - ANSstatement provides a method to more clearly represent such branching tand - ANStangent of argument in degrees
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved