How to modify the command "find" to make it find values in interval?

1 回表示 (過去 30 日間)
Ismail Qeshta
Ismail Qeshta 2018 年 2 月 21 日
コメント済み: Ismail Qeshta 2018 年 2 月 21 日
Hi,
The following is for a threshold value. The detects all values larger than a certain "threshold" value (in the code below it is 0.0193364). However, I need it to detect values between interval, for example, any value between 0 and 0.012.
Could anyone please help me? Thank you very much.
The code:
numfiles = 456;
threshold =0.0193364;
linesabovethreshold = zeros(numfiles, 1);
for fileidx = 1:numfiles
filecontent = dlmread(sprintf('result_%d.txt', fileidx));
assert(iscolumn(filecontent), 'file number %d has more than one column', fileidx);
linesabovethreshold(fileidx) = sum(filecontent >= threshold); %only works if file has only one column
end
dlmwrite('Fragility_mm.txt', linesabovethreshold / 1000);

採用された回答

Birdman
Birdman 2018 年 2 月 21 日
Try this:
numfiles = 456;
low=0;up=0.012;
linesabovethreshold = zeros(numfiles, 1);
for fileidx = 1:numfiles
filecontent = dlmread(sprintf('result_%d.txt', fileidx));
assert(iscolumn(filecontent), 'file number %d has more than one column', fileidx);
linesabovethreshold(fileidx) = sum(filecontent >= low & filecontent <= up); %only works if file has only one column
end
dlmwrite('Fragility_mm.txt', linesabovethreshold / 1000);
  3 件のコメント
Birdman
Birdman 2018 年 2 月 21 日
It is included as you can see there is a equality sign as well in the condition.
filecontent <= up
Ismail Qeshta
Ismail Qeshta 2018 年 2 月 21 日
Great. Thank you very much Birdman. Your insightful responses were awesome as usual.

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by