Problems with min and max functions
Afficher commentaires plus anciens
I am currently doing a project where I have to make x and y equal to 100 random numbers, and then find the max and min of both x and y. I have a maximum value function and a minimum value function, but for some reason, whenever I run the code, nothing appears in the command window. No errors are showing up, so I am not quite sure why nothing is being displayed.
%Generate two arrays of 100 numbers each
x=randi([-9999,9999],10,10);
y=[];
y=[y,2.5+1*rand(10)]
%%
%Process the two arrays and determine:
%The largest and smallest values in x and y:
function max=maxval(x)
x=randi([-9999,9999],10,10);
i=length(x);
max=(x(1));
if (max)<(x(i))
max=(x(i))
end
disp(max)
end
function min=minval(x)
x=randi([-9999,9999],10,10);
min=x(1)
if min>(x(i))
min=(x(i))
end
end
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Entering Commands dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!