how to count a sequence of data arrays with cut off?
이전 댓글 표시
i have 5 data in one array. For example, the data array [2.33 2.00 1.60 1.59 1.99]. If the cutoff is 1.50, it means the amount of data is 4 (pay attention to the order of the data). the number 1.99 in the 5th index is not counted.
This is my code
cnr_all=[2.33 2.00 1.60 1.59 1.99];
cut_off=1.50;
N=zeros(size(cnr_all));
for i=1:numel(cnr_all)
if cnr_all[i] >= cut_off;
N=N+1;
break;
end
end
disp(N)
댓글 수: 5
Pratyush Swain
2024년 5월 16일
Hi Rahmat,
Can you explain why the 5th index element(1.99) is not included ? Because the first four elements are also greater than the cut off. Can you explain clearly how does this cutoff workflow/method work ?
% e.g. array
cnr_all=[2.33 2.00 1.60 1.45 1.99];
% cut-off
cut_off=1.50;
N=0;
for i=1:numel(cnr_all)
if cnr_all(i) >= cut_off;
N=N+1;
%break; %comment the break
end
end
disp(N)
rahmat
2024년 5월 16일
rahmat
2024년 5월 16일
rahmat
2024년 5월 16일
채택된 답변
추가 답변 (1개)
hello
why not simply this ?
% example 1
cnr_all=[2.33 2.00 1.60 1.59 1.99];
cut_off=1.50;
[~,N] = min(cnr_all - cut_off)
% example 2
cnr_all=[2.33 2.00 1.60 1.51 1.53];
cut_off=1.50;
[~,N] = min(cnr_all - cut_off)
댓글 수: 5
rahmat
2024년 5월 16일
rahmat
2024년 5월 16일
Mathieu NOE
2024년 5월 16일
well, I believed I understood yor goal - as you described above
because I want a trend in the data. For example, there is data from the largest to the smallest (cutoff), but after the smallest data (cutoff) there is data that exceeds the cutoff value. This data is ignored.
but what would you expected in this new case ?
%example array
data_array = [2.33, 2.00, 1.60, 1.59, 1.99];
% Cutoff value
cutoff_value = 2.00;
rahmat
2024년 5월 16일
Mathieu NOE
2024년 5월 16일
ok - still I'd like to have from you what then is expected in that case :
%example array
data_array = [2.33, 2.00, 1.60, 1.59, 1.99];
% Cutoff value
cutoff_value = 2.00;
카테고리
도움말 센터 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!