Write a function in Matlab to accept both ordinary numeric a
Write a function in Matlab to accept both ordinary numeric arrays and cell arrays containing numeric values. Verify that your function works by passing the following input variables.
I. a = [3 5 1], b = [ 2 1 3; 5 2 2 ]
II. a = [3 5 1], c{1} = 5
III. a = [3 5 1], b = [ 2 1 3; 5 2 2 ], c{1} = 5, c{2} = [ 1; 2 ], c{3} = [ 2 3; 4 5 ]
Solution
%Matlab script
function [ Y ] = passArray( C )
%PASSARRAY Summary of this function goes here
% Detailed explanation goes here
Y=C;
end
Results
>> a = [-3 5 -1];
>> passArray( a )
ans =
-3 5 -1
>> b = [ 2 -1 3; 5 2 -2 ]
b =
2 -1 3
5 2 -2
>>
>> passArray( b )
ans =
2 -1 3
5 2 -2
passArray( c )
ans =
[5]
>> c{1} = 5; c{2} = [ 1; 2 ]; c{3} = [ 2 -3; -4 5 ]
c =
[5] [2x1 double] [2x2 double]
>> passArray( c )
ans =
[5] [2x1 double] [2x2 double]
