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 BASIC PROGRAMMING. QUESTIONS & CORRECTANSWERS.2025 ALREADY GRADED A+..pdf, Exams of Nursing

MATLAB BASIC PROGRAMMING. QUESTIONS & CORRECTANSWERS.2025 ALREADY GRADED A+..pdf

Typology: Exams

2024/2025

Available from 07/15/2025

kinuthia-mbiukia
kinuthia-mbiukia 🇬🇧

3

(2)

478 documents

1 / 15

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
MATLAB BASIC PROGRAMMING.
QUESTIONS & CORRECTANSWERS
2025. 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]
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download MATLAB BASIC PROGRAMMING. QUESTIONS & CORRECTANSWERS.2025 ALREADY GRADED A+..pdf and more Exams Nursing in PDF only on Docsity!

MATLAB BASIC PROGRAMMING.

QUESTIONS & CORRECTANSWERS

2025. 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

allTrue = true - ANSall true any(inArray) - ANSidentifies whether any array elements are non-zero or true, and false otherwise. Instead of testing elements along the columns, any(inArray, 2) tests along the rows. The function call any(inArray,1) is equivalent to any(inArray). any(x) - ANSReturns true if x is nonzero; otherwise, returns false. array - ANSa matrix is a rectangular array of items in rows and columns; is an ordered sequence of items of a given data type asin - ANSinverse sine asind - ANSinverse sine, results in degrees asinh - ANSinverse hyperbolic sine assignment operator - ANSThe '=' is kn own as the ______. assignment statement - ANSsuch as age = 20; upon being executed, writes the current value of the item on the ='s right side into the variable on the ='s left side. atan2 - ANSfour quadrant inverse tangent boolean value - ANSlogical value aka ______ ______. char(numericArray) - ANSconverts the numeric array numericArray into a character vector charVec2 corresponding to the Unicode transformation format 16 (UTF-16) code. char(stringScalar) - ANSconverts the string scalar stringScalar into a character vector charVec1. clc - ANSClears the command window. Does not affect the workspace, meaning variables are unchanged clear - ANSclears all variables from the workspace, so all variable values are lost. close(n) - ANScloses figure number n

comment - ANSThe interpreter ignores all text to the right of "%" on a line, so the programmer can write any text there. compose(formatSpec,arrayIn) - ANSformats the data in arrays arrayIn, using formatting operators specified by formatSpec and returns the resulting text in stringArrayOut. The compose function formats values from arrayIn in column order. contains(String1,TestPattern) - ANSperforms a case-sensitive logical comparison returning 1 (true) if scalar array string1 contains the specified testPattern, and returns 0 (false) otherwise. If testPattern is a string array containing multiple patterns, then contains returns 1 if string1 contains any element of testPattern. contains(string1, testPattern, 'IgnoreCase',true) ignores case when determining if string1 contains testPattern. cos - ANScosine cosd - ANScosine in argument of degrees cosh - ANShyperbolic cosine cot - ANScotangent 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.

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

isstrprop returns a cell array of logical vectors. Frequently-used values for categoryStrings include: 'alpha' for elements that are alphabetic. 'alphanum' for elements that are alphanumeric. 'digit' for elements that are numbers. 'lower' for lowercase characters. 'punct' for Punctuation characters. 'upper' for uppercase characters. 'wspace' for whitespace characters, including {' ', '\t', '\n', '\r', '\v', '\f'}. isvector(inArray) - ANStests for a vector/1D array. j - ANSImaginary unit equal to sqrt(-1), same as i keywords - ANSbreak, else, global, return, case, else if, if, epode,catch, end, otherwise, switch, classdef, for, parlor, try, continue, function, persistent, while length() - ANSreturns the number of elements along the largest dimension of inArray. Often used to find length of a 1D array. literal constant - ANSa number that appears in a statement log - ANSnatural logarithm log10 - ANScommon (base 10) logarithm loglog - ANSLine plot with logarithmic x and y axes. MATLAB is a high-level language that excels at creating exceptionally fast-executing programs - ANSFalse - it supports scientific and engineering computations MATLAB was developed in the late 1950's - ANSFalse - 1970 NaN - ANSNot-a-Number ndims( ) - ANSreturns the number of array dimensions. ndims(inputArray) - ANS______ returns the number of dimensions in the array inputArray.

no conversion specification is needed - ANSTo right justify the output, _________. nthroot - ANSreal n-th root of real numbers numel( ) - ANSreturns the number of array elements. numeric variable - ANSstores a number orient - ANSspecifies the orientation of a figure Overflow - ANSoccurs when the result of a expression exceeds the maximum value that can be stored within a variable. 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.

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 string 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 tanh, sech, csch, coth, - ANStrig functions that are hyperbolic The final number is: - ANSfprintf('The final number is:'); tril(A) - ANSReturns the lower triangular part of an array.