Make an awesome ramp for a tiny motorcycle stuntman | MATLAB CODY Problem
Given a vector, say v=[1 3 6 9 11], turn it into a matrix 'ramp' like so:
m=[1 3 6 9 11; 3 6 9 11 0; 6 9 11 0 0; 9 11 0 0 0; 11 0 0 0 0]
That way a tiny motorcycle stuntman can follow the trace and jump over 9 school buses safely.
The problem is taken form MATLAB CODY , you can check the problem in the below link also:
Click here
The problem is taken form MATLAB CODY , you can check the problem in the below link also:
Click here
MATLAB CODE:
Main Body:
clc
clear all
close all
x=input('Enter the array:');
r=length(x);
z=[];
z=[z x'];
for i=1:length(x)-1
x=ci(x);
z=[z x'];
end
Function:
function y=ci(x)
z=length(x);
y=[];
for i=2:length(x)
y=[y x(i)];
end
c=length(y);
for i=length(y)+1:z
y=[y 0];
end
end
Explanation:
Sample Output:
Output 1:
Output 2:
No comments