Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MatLab Problem 2: Functions Write a function [row, col, varClass, flag] = descri

ID: 3870615 • Letter: M

Question

MatLab

Problem 2: Functions

Write a function [row, col, varClass, flag] = describeVar(var) that accepts a variable (var) and returns the number of rows (row), the number of columns (col), the class of the data in the var (varClass), and a logical value (flag) that says whether any of the data in varis NaN or Inf. HINT! Use isnan or isinf to determine if data is NaN or Inf
Test Examples:

>> var = NaN;

>>[row, col, varClass, flag] = describeVar(var)

row = 1

col = 1

varClass = double

flag = 1

>> var = [7, 3, 4, 9]

>>[row, col, varClass, flag] = describeVar(var)

row = 1

col = 4

varClass = double

flag = 0


Explanation / Answer

// write this function in script file save as describeVar.m

function [row,col,varClass,flag] = describeVar (var)
row = size(var,1)
col = size(var,2)
varClass = class(var)
flag = isnan(var)

endfunction

// After that in command line type these..

var = NaN

//Then press Enter .After that call the function

describeVar(var)