Azzera filtri
Azzera filtri

How to find the value closest to 1 from a x*y*z double matrix ?

1 visualizzazione (ultimi 30 giorni)
I have to find the values for k according to the following code. When I execute the following code I get a 18x12x6 double to k. From that how can I find the exact p,n and m which is corresponding a value which is closest to 1 from matrix k??
I1= 8.0742;
I2=4.85;
I3=2.4293;
for p=1:18
for n=1:12
for m=1:6
k(p,n,m) = p*I1/(n*I2+m*I3);
end
end
end

Risposta accettata

Stephen23
Stephen23 il 28 Ott 2018
Modificato: Stephen23 il 28 Ott 2018
>> [~,x] = min(abs(k(:)-1));
>> [p,n,m] = ind2sub(size(k),x)
p = 6
n = 9
m = 2
>> k(p,n,m)
ans = 0.99869
  5 Commenti
Stephen23
Stephen23 il 30 Ott 2018
Use sort instead of min, and pick as many as you want:
>> [v,x] = sort(abs(k(:)-1));
>> [p,n,m] = ind2sub(size(k),x(1:3)) % first three
p =
6
3
6
n =
9
4
8
m =
2
2
4
>> k(p(1),n(1),m(1))
ans = 0.99869
>> k(p(2),n(2),m(2))
ans = 0.99852
>> k(p(3),n(3),m(3))
ans = 0.99852

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Computational Geometry in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by