Line selection if the temperature difference does not change?

1 回表示 (過去 30 日間)
Sarlota Duskova
Sarlota Duskova 2020 年 10 月 17 日
コメント済み: Adam Danz 2020 年 10 月 17 日
Hello, I am using Matlab R2020b. I would like to ask how to find differences in column with temperature that have difference 0.0 or 0.01. I am reading data from .xls file, my code is this, but it doesnot look thats work well because sometimes when it is 0.01 it show 1 and sometimes 0:
difference = diff(TT.M01__C)
Adif = (abs(difference) <= 0.01)
Then I would like to ask if it is possible count that is number 1 in logical array is consecutively 15 times or more and say which row it start it. Because I need to find interval where the temperature doesnot change with that differences. I did this but I think it doesnot work properly because the problem above doesnot work good.
stps = 1:numel(Adif) % Step Counter
zv = stps(diff(Adif <= 0.01) > 0)
validRegions = zv(diff(zv) > 15)

採用された回答

Adam Danz
Adam Danz 2020 年 10 月 17 日
"sometimes when it is 0.01 it show 1 and sometimes 0"
This is likely due to round-off error. For example,
x = 0.01000001
x = 0.0100
x <= 0.01
ans = logical
0
" count [the number of consecutive 1s] in logical array ... 15 times or more and [return the starting row]"
  2 件のコメント
Sarlota Duskova
Sarlota Duskova 2020 年 10 月 17 日
Thank you for your quick help, I used round function to decimal so then my first question works. Then I adopted your answer for second problem so now is it perfect.
Adam Danz
Adam Danz 2020 年 10 月 17 日
Socially distant high-five! ✋

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2020 年 10 月 17 日
To find out if you have stretches of 1's in Adif that are 15 or longer, you can use regionprops
Adif = [1, 0, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 0, 0, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 0, 0, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 0, 1,1];
props = regionprops(logical(Adif), 'Area', 'PixelIdxList'); % Measure lengths of all runs of 1's.
allLengths = [props.Area] % Extract all the lengths into one double vector.
% Print out all runs where the length is 15 or more.
starts15 = [];
for k = 1 : length(allLengths) % For every region...
if allLengths(k) >= 15 % If that region is 15 elements or longer...
% Print it out to the command window.
fprintf('Region %d is %d elements long and starts at index %d.\n', ...
k, allLengths(k), props(k).PixelIdxList(1));
% Save this index of this run
starts15 = [starts15, props(k).PixelIdxList(1)];
end
end
You'll see
allLengths =
1 15 18 17 2
Region 2 is 15 elements long and starts at index 3.
Region 3 is 18 elements long and starts at index 20.
Region 4 is 17 elements long and starts at index 40.

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by