Posts

How to check class of variable is struct in MatLab? - isstruct -- MatLab

 How to check class of variable is struct in MatLab? - isstruct -- MatLab How to check class of variable is struct in MatLab? [Ans] isstruct [description] <answer>=isstruct(<s1>) If <s1> is a structure, it will return true. Otherwise, return false. more details on: Determine if input is structure array - MATLAB isstruct (mathworks.com) code: clear clc s1=struct s2=struct([]) s3=struct( 'a' , '1' ) s4=struct( 'a' ,[1 2]) s5=struct( 'a' ,[[1] [2]]) s6=struct( 'a' ,[[ '1' ] [ '2' ]]) s7=struct( 'a' ,1, 'b' ,2, 'c' ,3) s8=struct( 'a' ,1, 'b' ,2, 'c' ,{3,4}) s8(1) s8(2) %compiler error %s8(3,1) %s8(3,2) s9=struct( 'a' ,{3,4}) s9(1) s9(2) s10=struct(s9) s11=s9 result: s1 = struct  with no fields. s2 = 0×0 empty struct  array with no fields. s3 = struct  with fields: a: '1' s4 = struct  with fields: a: [1 2] s5 = struct  with fields: a...

Is a matrix same as a vector in MatLab? -- MatLab

 Is a matrix same as a vector in MatLab? -- MatLab Is a matrix same as a vector in MatLab? [Ans] No [NOTE] But I found and interesting thing. A vector will be recognized as a vector and a matrix. i.e. For a vector named vec, isvector(vec) will return true and ismatrix(vec) will return true. Look at following example(code and output). code: clear clc A=[1:3:7;1:2:5] fprintf( "A: Is it a matrix?" +ismatrix(A)+ "\t" + "Is it a vector?" +isvector(A)); fprintf( "\n" ); vec=[1:2:8] fprintf( "vec: Is it a matrix?" +ismatrix(vec)+ "\t" + "Is it a vector?" +isvector(vec)); fprintf( "\n" ); output: A = 1 4 7 1 3 5 A: Is it a matrix?true Is it a vector?false vec = 1 3 5 7 vec: Is it a matrix?true Is it a vector?true