필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
Eranja Noopehewa
Eranja Noopehewa 2018년 10월 28일
댓글: Eranja Noopehewa 2018년 10월 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에서 Computational Geometry에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by