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 Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by