Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Solution 354530

Submitted on 18 Nov 2013 by J-G van der Toorn

Correct

71Size
Leading solution size is 25.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test
Code Input and Output
1
Pass
 
%%
s = 'function foo()';
inNames_correct = {};
outNames_correct = {};
[inNames, outNames] = get_variable_names(s);
assert(isequal(inNames,inNames_correct))
assert(isequal(outNames,outNames_correct))

                    
2
Pass
 
%%
s = 'function a = foo(b)';
inNames_correct = {'b'};
outNames_correct = {'a'};
[inNames, outNames] = get_variable_names(s);
assert(isequal(inNames,inNames_correct))
assert(isequal(outNames,outNames_correct))

                    
3
Pass
 
%%
s = 'function [myOutput] = foo(b,c)';
inNames_correct = {'b';'c'};
outNames_correct = {'myOutput'};
[inNames, outNames] = get_variable_names(s);
assert(isequal(inNames,inNames_correct))
assert(isequal(outNames,outNames_correct))

                    
4
Pass
 
%%
s = 'function [A,B] = foo(c,d,f)';
inNames_correct = {'c';'d';'f'};
outNames_correct = {'A';'B'};
[inNames, outNames] = get_variable_names(s);
assert(isequal(inNames,inNames_correct))
assert(isequal(outNames,outNames_correct))

                    
5
Pass
 
%%
s = sprintf('function %s=...\nmyfun %s...\n  %s\n%% With comments[]()\nandCode = 4*[1 3 4/(1+2)];',...
'[how,about , several,outputs]',...
'(and , several, inputs ,',...
'split,over,lotsOf,lines)');
inNames_correct = {'and';'several';'inputs';'split';'over';'lotsOf';'lines'};
outNames_correct = {'how';'about';'several';'outputs'};
[inNames, outNames] = get_variable_names(s);
assert(isequal(inNames,inNames_correct))
assert(isequal(outNames,outNames_correct))