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 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