Line selection if the temperature difference does not change?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Sarlota Duskova
am 17 Okt. 2020
Kommentiert: Adam Danz
am 17 Okt. 2020
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 Kommentare
Akzeptierte Antwort
Adam Danz
am 17 Okt. 2020
"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 Kommentare
Weitere Antworten (1)
Image Analyst
am 17 Okt. 2020
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 Kommentare
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!