Type the following in the command window and submit the results. Briefly explain what each assignment does.
a = 1
b = 'x'
c = true
whos a b c
a == c
a + c
d = [1 2 3 4]
e = ['a' 'b' 'c' 'd']
f = ['a','b','c','d']
g = ['abcd']
h = {‘a’ ‘b’ ‘c’ ‘d’}
i = { a b c d}
whos d e f g h i
class(a)
type(a)
True
true
False
false
a = 1 % assigns value 1 to a
b = 'x' % assigns character 'x' to b
c = true % assigns logical value true to variable c
whos a b c % prints a description of the variables a b c
a == c % evaluates whether a euqals b
a + c % returns sum of a and c
d = [1 2 3 4] % creates a real array
e = ['a' 'b' 'c' 'd'] % creates a string 'abcd'
f = {'a','b','c','d'} % creates a cell array of the input 4 characters
g = ['abcd'] % creates a string 'abcd'
h = {‘a’ ‘b’ ‘c’ ‘d’} % syntax error due to use of undefined characters ‘ and ’
i = { a b c d} % creates a cell array from the four input variables
whos d e f g h i % prints a description of the variables d e f g h i
class(a) % returns the type of the variable a
type(a) % syntax error: input arguments to type() must be character vectors or strings
True % syntax error: undefined variable
true % logical value true in MATLAB
False % syntax error: undefined variable
false % logical value false in MATLAB
In Python, many of the above commands would yield syntax errors, however, they can be easily fixed with minor tweaks.