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 169363

Submitted on 27 Nov 2012 by Evan

Correct

23Size
Leading solution size is 21.
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
 
%%
global gOffset global_x
gOffset=4;
global_x=1024;
a=2;
b=4;
[a_off b_times] = use_global(a,b);
gOffset=4;
global_x=1024;
assert(isequal(a_off,gOffset+a))
assert(isequal(b_times,global_x*b))

                    
2
Pass
 
%%
global gOffset global_x
gOffset=-8;
global_x=-2;
a=50;
b=-21;
[a_off b_times] = use_global(a,b);
assert(isequal(a_off,gOffset+a))
assert(isequal(b_times,global_x*b))

                    
3
Pass
 
%%
global gOffset global_x
gOffset=2^12;
global_x=3;
a=randi(128);
b=randi(8);
[a_off b_times] = use_global(a,b);
assert(isequal(a_off,gOffset+a))
assert(isequal(b_times,global_x*b))