Problem finding the nearest value to specific number

조회 수: 2 (최근 30일)
Jose Rego Terol
Jose Rego Terol 2020년 1월 19일
댓글: Jose Rego Terol 2020년 1월 22일
Hello,
I am using this code seen in this thread:
%Initial amplitud (50%time - 10%time)
time_10=((max(A)-min(A))*0.1)+min(A);
time_50=((max(A)-min(A))*0.5)+min(A);
[~,~,idx]=unique(abs(A-time_10));
[~,~,idx2]=unique(abs(A-time_50));
minVal_10=A(idx==1);
minVal_50=A(idx2==1);
T10=find(A==minVal_10); %Gives you the row where 10% of the time lies in the Intensity matrix
T50=find(A==minVal_50); %Gives you the row where 50% of the time lies in the Intensity matrix
I_T10=B1(T10,1);
I_T50=B1(T50,1);
ini_Amp=(I_T50-I_T10)*10^6;
However, I have problems with minVal_50. there are two values equally near to time_50. Therefore I got this warning:
Matrix dimensions must agree.
Error in foot_signal_analysis1 (line 60)
T50=find(A==minVal_50); %Gives you the row where 50% of the time lies in the Intensity matrix
T50=10.53350, and minVal_50 is either 10.53352 or 10.53348. How can I code to take the biggest number in this case? If statement?

답변 (1개)

Jose Rego Terol
Jose Rego Terol 2020년 1월 19일
I've tried with this, but I got an empty box for my parameter "ini_amp". So, the reasoning behind this code was to use "size" in order to get the highest (or lowest, regarding the variable) number if the size is higher than 1. For example, if there are more than one values for minVal_10, the if statement takes the min value for minVal_10
value10=size(minVal_10);
if value10~1;
value10==min(minVal_10);
else value10==minVal_10;
end
minVal_50=A(idx2==1);
value50=size(minVal_50);
if value50~1;
value50==max(maxVal_50);
else value50==maxVal_50;
end
T10=find(A==value10); %Gives you the row where 10% of the time lies in the Intensity matrix
T50=find(A==value50); %Gives you the row where 50% of the time lies in the Intensity matrix
I_T10=B1(T10,1);
I_T50=B1(T50,1);
ini_Amp=(I_T50-I_T10)*10^6;
  댓글 수: 1
Jose Rego Terol
Jose Rego Terol 2020년 1월 22일
I solved using function max.
It had an easy solution.

댓글을 달려면 로그인하십시오.

카테고리

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