Line selection if the temperature difference does not change?

1 次查看(过去 30 天)
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.

请先登录,再进行评论。

更多回答(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 CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by