Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
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

Respuesta aceptada

Stephen23
Stephen23 el 28 de Oct. de 2018
Editada: Stephen23 el 28 de Oct. de 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 comentarios
Stephen23
Stephen23 el 30 de Oct. de 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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Computational Geometry en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by