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

1 次查看(过去 30 天)
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

采纳的回答

Stephen23
Stephen23 2018-10-28
编辑:Stephen23 2018-10-28
>> [~,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 个评论
Stephen23
Stephen23 2018-10-30
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by