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)
댓글 수: 0
채택된 답변
Adam Danz
2020년 10월 17일
"sometimes when it is 0.01 it show 1 and sometimes 0"
x = 0.01000001
x <= 0.01
" count [the number of consecutive 1s] in logical array ... 15 times or more and [return the starting row]"
댓글 수: 2
추가 답변 (1개)
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!