Load multiple files to MATLAB without changing name manually
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Yew Jen Chong
le 13 Juin 2022
Commenté : Yew Jen Chong
le 14 Juin 2022
Hello, I have written a program for signal analyzing and I want to apply it to different files. Is there any ways to upload multiple files automatically without the needs of changing the file name manually as shown below?
cm = readtable('signal1.csv', 'VariableNamingRule','preserve');
Thank you if someone can assist me.
Réponse acceptée
Chunru
le 13 Juin 2022
% list the files to be processed
fn = dir("signal*.csv");
for ifile=1:length(fn)
current_fn = fn(ifile).name;
% [file,path]=uigetfile('*.csv','MultiSelect','on');
cm = readtable(current_fn, 'VariableNamingRule','preserve');
cmVar = cm.Properties.VariableNames;
figure
plot(cm{:,1},cm{:,[2 3]})
grid
xlabel(cmVar{1})
legend(cmVar{[2 3]}, 'Location','best')
title('Original Signal')
env1 = envelope(cm{:,2}, 250, 'peak');
figure
plot(cm{:,1},cm{:,[2 3]})
hold on
plot(cm{:,1},env1,'LineWidth',2)
hold off
grid
xlabel(cmVar{1})
legend(cmVar{[2 3]},'Envelope','Location','best')
title('Original Signal with Envelope')
Threshold = 5;
Lv = env1 >= Threshold;
figure
plot(cm{Lv,1},cm{Lv,[2 3]})
grid
xlabel(cmVar{1})
legend(cmVar{[2 3]},'Location','best')
title('Edited Signal')
figure
Fs = 1/cm{2,1};
findpeaks(cm{Lv,2},Fs,'MinPeakDistance',0.016,'MinPeakProminence',15,'MinPeakHeight',15);
[pksRT,locsRT] = findpeaks(cm{Lv,2},Fs,'MinPeakDistance',0.016,'MinPeakProminence',15,'MinPeakHeight',15);
pksRT1 = num2cell(pksRT);
legend(cmVar{2},'Location','bestoutside')
text(locsRT,pksRT+5,pksRT1,'FontSize',8,'Rotation',90)
Period = diff(locsRT);
Period_mean = mean(Period);
Period_min= min(Period);
Period_max = max(Period);
impact= table (Period);
impact.Frequency = (1./Period)*60;
torque_rms = rms(cm{Lv,"Reaction Torque [Nm]"});
current_rms = rms(cm{Lv,"Current RMS [amp]"});
Step_res=stepinfo(cm.("Reaction Torque [Nm]"),cm.("Time [s]"))
Area_torque=cumtrapz(cm{Lv,"Time [s]"},cm{Lv,"Reaction Torque [Nm]"});
Overall_data = table(torque_rms,current_rms, Period_max, Period_min, Period_mean);
Overall_data.Area_torque = Area_torque(end);
% writetable (Overall_data, 'ML_Data.csv')
% writetable (impact, 'ML_Data.csv')
end
1 commentaire
Plus de réponses (1)
Karim
le 13 Juin 2022
Hey, you can read the data via a loop, see below.
Best regards
numFiles = 3;
for nF = 1:numFiles
cm = readtable(['signal',num2str(nF),'.csv'], 'VariableNamingRule','preserve');
% put other process code here
end
0 commentaires
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!