bsxfun - @minus - how to divide by maximum
Mostra commenti meno recenti
Hello everyone,
I have two arrays:
a = [1; 2; 3]
b = [1; 2; 3; 4]
out = abs(bsxfun(@minus,a,b')./a)
I am getting this:
out = [0 1 2 3
0.5 0 0.5 1.0
0.67 0.33 0 0.33]
I am looking for a way to divide not simply by ./a, but to divide by the maximum number in the numerator. So instead of calculating abs(1-3)/1=2 for out(1,3) I would like the calculation to be abs((1-3)/3)=0.67.
Any help is greatly appreciated.
Risposta accettata
Più risposte (1)
Geoff Hayes
il 28 Dic 2020
Ko - if you want to divide by the maximum of a, couldn't you just do
out = abs(bsxfun(@minus,a,b')./max(a))
?
3 Commenti
Ko Fa
il 28 Dic 2020
Sean de Wolski
il 28 Dic 2020
But max of a is 5. So where does the 4 come from??
Also, you don't need bsxfun.
abs((a-b')/max(a))
Ko Fa
il 28 Dic 2020
Categorie
Scopri di più su Mathematics in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!