Find automatically data of interest
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello everyone,
I havew a question about how to improve my code.
I have a time-Temperature profile that is a bit noisy: my goal is to automatically find the heating, cooling and isotheramal portions by only looking at the first derivative of the temperature with respect to the time. Unluckily, the code is not perfect but I don't know how to improve it: can anyone help me?
Attached you can fine the test data and the code I use together with the subroutines.
close all
clear
tic
load 'conv_ageing_atm5_m60p80_01to2048s_bif_74165.txt'
conv_ageing_atm5_m60p80_01to2048s_bif_74165;
t=conv_ageing_atm5_m60p80_01to2048s_bif_74165(1:end,2);
T=conv_ageing_atm5_m60p80_01to2048s_bif_74165(1:end,3);
Cp=conv_ageing_atm5_m60p80_01to2048s_bif_74165(1:end,4);
time=conv_ageing_atm5_m60p80_01to2048s_bif_74165(1:end,5);
un=[1:1:length(T)];
ratew=(gradient(T)./gradient(time));
rate=smoothdata(ratew,'movmedian',30);
rate=nearest(rate);
flag=zeros(length(T),1);
for i=1:length(T)
if rate(i)>0;
flag(i)=1;
else if rate(i)==0;
flag(i)=0;
else if rate(i)<0;
flag(i)=-1;
end
end
end
end
[y]=remove_outliers(flag);
figure(1)
plot(un,flag,'o')
hold on
plot(un,y,'ro')
[Aw,Bw,Cw]=group_data(y);%Aw=heating/Bw=isother/Cw=cooling
[Vw]=organize_vector(Aw);%heating
[Uw]=organize_vector(Bw);%isotherm
[Ww]=organize_vector(Cw);%cooling
formatSpec = 'You have %d heating scans\n';
fprintf(formatSpec,length(Vw))
formatSpec2 = 'You have %d isotherms\n';
fprintf(formatSpec2,length(Uw))
formatSpec3 = 'You have %d cooling scans\n';
fprintf(formatSpec3,length(Ww))
toc
5 Kommentare
Antworten (1)
Jan
am 25 Okt. 2022
Some methods are "ugly":
load 'conv_ageing_atm5_m60p80_01to2048s_bif_74165.txt'
Loading data directly into the workspace creates variables dynamically. This impedes Matlab's JIT acceleration and the debugging. Prefer to load data into a specific variable:
Data = load('conv_ageing_atm5_m60p80_01to2048s_bif_74165.txt');
This line is a waste of time only:
conv_ageing_atm5_m60p80_01to2048s_bif_74165;
Use a less painful name for variables. Hiding important information in the name of variables is a programming anti-pattern:
value = Data.conv_ageing_atm5_m60p80_01to2048s_bif_74165;
Use ":" instead of "1:end", because it is faster:
% Replace: t = conv_ageing_atm5_m60p80_01to2048s_bif_74165(1:end,2); by
t = value(:, 2);
Replace the code:
flag=zeros(length(T),1);
for i=1:length(T)
if rate(i)>0;
flag(i)=1;
else if rate(i)==0;
flag(i)=0;
else if rate(i)<0;
flag(i)=-1;
end
end
end
end
by
flag = sign(rate);
[] is Matlab's operator for a concatenation of arrays. In
un=[1:1:length(T)];
you concatenate the vector 1:length(T) with nothing. Cleaner and faster:
un = 1:length(T);
Siehe auch
Kategorien
Mehr zu Biomedical Imaging 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!