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:

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: [1 2]


s6 =

struct with fields:

a: '12'


s7 =

struct with fields:

a: 1
b: 2
c: 3


s8 =

1×2 struct array with fields:

a
b
c


ans =

struct with fields:

a: 1
b: 2
c: 3


ans =

struct with fields:

a: 1
b: 2
c: 4


s9 =

1×2 struct array with fields:

a


ans =

struct with fields:

a: 3


ans =

struct with fields:

a: 4


s10 =

1×2 struct array with fields:

a


s11 =

1×2 struct array with fields:

a

Comments

Popular posts from this blog

How to check a type of specified variable is a specified type in MatLab? - isa -- MatLab