MATLAB traversing an Array Write your own script that will f
MATLAB traversing an Array
Write your own script that will find the minimum element of an array. You CANNOT use the build-in function, min(). Your script will start with generating a 20 by 20 array consisting of random integers in the range [-100,100]. If will then loop through all element and find the min value of all. This is 4 based on the problem #3. In addition to finding the smallest number, this program will also count the occurrences of the smallest number. You cannot use build-in functions. You are going to traverse the array and count This is another variation of problem #3. Instead of finding the smallest number, this program will look for the two smallest numbers. (They can be of the same value). You cannot use build-in functions. You are going to traverse the array and look for the two mins.Solution
3.
x=100*rand(20,20)
[m n]=size(x);
min=0;
for i = 1:n
for j=1:m
if (x(i,j)<min)
min=x(i,j);
else
min=min;
end
end
min
_______________________________________________________________
4.
x=100*rand(20,20)
[m n]=size(x);
min=0;
for i = 1:n
for j=1:m
if (x(i,j)<min)
min=x(i,j);
else
min=min;
end
end
count=0;
for i=1:n
for j=1:m
if(x(i,j)==min)
count=count+1;
end
end
end
count
________________________________________________________________
x=100*rand(20,20)
[m n]=size(x);
min1=0;
min2=0;
for i = 1:n
for j=1:m
if (x(i,j)<min1)
min1=x(i,j);
else
min1=min1;
end
end
min1
for i=1:n
for j=1:m
if(x(i,j)<min2 &&x(i,j)>min1)
min2=x(i,j);
end
end
min2

