Problem 1451. Symmetry of vector
function y = symmetry(x)
n=length(x);
for i=1:n
if x(i)==x(n-i+1)
y=1;
else
y=0;
end
end
end
Problem 1430. Create an n-by-n null matrix and fill with ones certain positions
unction a = FillWithOnes(n,mat)
m=size(mat,1);
a = zeros(n);
for i=1:m
b=mat(i,:);
c=b(1,1);
d=b(1,2);
a(c,d)=1;
end
end
Problem 33. Create times-tables
function m = timestables(x)
for i=1:x
m(i,:)=i:i:i*x;
end
end
Problem 645. Getting the indices from a vector
function out = findIndices(vec, thresh)
out =find(vec>thresh);
end
Problem 10. Determine whether a vector is monotonically increasing
function tf = mono_increase(x)
if isempty(find(diff(x)<=0))
tf = true;
else
tf = false;
end
Problem 838. Check if number exists in vector
function y = existsInVector(a,b)
if any(find(b(:)==a))==1
y=1;
else
y=0;
end
Problem 19. Swap the first and last columns
function B = swap_ends(A)
m=size(A,1);
n=size(A,2);
B=zeros(m,n);
for i=1:n
if i==1
B(:,i)=A(:,end);
elseif i==n
B(:,end)=A(:,1);
else
B(:,i)=A(:,i);
end
end
end
Problem 262. Swap the input arguments
function [q,r] = swapInputs(a,b)
[q,r] = deal(b,a);
end
Problem 7. Column Removal
function B = column_removal(A,n)
A(:,[n]) = [];
B=A;
end
Problem 2015. Length of the hypotenuse
function c = hypotenuse(a,b)
c = sqrt(a^2+b^2);
end