min and max of a vector

I have 4 variables A, B, C, D
All 4 variables are a 1x20 vector containing random numbers
What i want to get is the minimum of a certain product
min(A*C,A*D,B*C,B*D)
where I get a 1x20 vector containing minimum values of the product.
I've tried
min(A*C,A*D,B*C,B*D) min(A*C',A*D',B*C',B*D')
but these don't seem to be the solution I"m looking for. Help??

1 commentaire

Jan
Jan le 26 Juin 2015
Did you read the documentation of min? You cannot provide 4 arrays as input. Please read the help and doc of a command.

Connectez-vous pour commenter.

Réponses (1)

Azzi Abdelmalek
Azzi Abdelmalek le 26 Juin 2015
Modifié(e) : Azzi Abdelmalek le 26 Juin 2015

0 votes

A=randi(20,1,20)
B=randi(20,1,20)
C=randi(20,1,20)
D=randi(20,1,20)
E=[A.*C;A.*D;B.*C;C.*D]
min(E)

6 commentaires

soloby
soloby le 26 Juin 2015
Thanks, this works out wonderfully. I need to do the same for division as well but if I do the same thing division will not work properly for some reason, do you know why that would be?
Could it be because my variable C and D have 1 value of 0 in both of them?
appreciate your help
Jan
Jan le 26 Juin 2015
@soloby: Please post your code and explain, what "will not work" means.
soloby
soloby le 26 Juin 2015
First if I try this:
H = [A/D,A/E,B/C,B/D];
I = min(H);
Warning: Rank deficient, rank = 3, tol = 3.368449e-14.
If I try this:
H = [A./D,A./E,B./C,B./D];
I = min(H);
Gives me a dimension error.
Error using ./ Matrix dimensions must agree.
Thank you for your help
Azzi Abdelmalek
Azzi Abdelmalek le 26 Juin 2015
Modifié(e) : Azzi Abdelmalek le 26 Juin 2015
A,B,C and D should be the same size, like in my example
A=randi(20,1,20)
B=randi(20,1,20)
C=randi(20,1,20)
D=randi(20,1,20)
E=[A./C;A./D;B./C;C./D]
min(E)
soloby
soloby le 26 Juin 2015
It is in the same size. my min(H) for multiplication works just fine but just the division does not work.
Walter Roberson
Walter Roberson le 26 Juin 2015
In H = [A./D,A./E,B./C,B./D]; where are you getting your E from? It is not one of your original variables. Azzi has created a temporary E which is 4 x 20 in order to find the min; if you were executing with that then it is not the same size as your other variables so of course you have problems.
You should be paying attention to the fact that Azzi used ; between the parts instead of comma. If you were to use H = [A./C,A./D,B./C,B./D]; to be consistent with your original question, then you would be getting a 1 x 80 vector and min() of that is going to give you a single result.

Connectez-vous pour commenter.

Question posée :

le 26 Juin 2015

Commenté :

le 26 Juin 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by