In: Computer Science
For the arrays x and y given below, use MATLAB to find all the elements in x that are greater than the corresponding elements in y.
x = [-3, 0, 0, 2, 6, 8] y = [-5, -2, 0, 3, 4, 10]
Using MATLAB method:
% declaring 2 arrays given
x = [-3, 0, 0, 2, 6, 8];
y = [-5,-2, 0, 3, 4, 10];
% looping through each element in x
% comparing with corresponding element in y
% printing if it is greater
for i=1:length(x)
if x(i)>y(i)
fprintf("%d ",x(i))
end
end
Sample Output
-3 0 6
Sample Output
-3 0 6