Auto Detect different file types?
Mostra commenti meno recenti
Hello,
I am trying to edit a program so that it is capable of auto detecting different text files. Currently, I am using two different pograms to open and report the seperate text files using the following bits of code:
Program 1:
filespec=[fpath char(fnameALL(2))]; TD=filespec;
delimiter='[\t]';comment='';quotes='';options='numeric';
[TDdata, ~]= readtext(filespec, delimiter, comment, quotes, options);
pVelocity = TDdata(6,62)*100; pCadence = (TDdata(6,21)+TDdata(6,48))/2;
pStride = TDdata(6,65)*100; pStepWidth = TDdata(6,68)*100;
pGSR=(pCadence/60)/(pVelocity/100);
pRTO = (TDdata(6,39)/TDdata(6,33))*100; pLTO = (TDdata(6,12)/TDdata(6,9))*100;
pRSS = (TDdata(6,30)/TDdata(6,33))*100; pLSS = (TDdata(6,57)/TDdata(6,9))*100;
pRSTEP = TDdata(6,42)*100; pLSTEP = TDdata(6,15)*100;
pROTO = (TDdata(6,36)/TDdata(6,33))*100; pLOTO = (TDdata(6,60)/TDdata(6,9))*100;
ToeOff = [pRTO pLTO];
filespec=[fpath char(fnameALL(3))]; TD=filespec;
delimiter='[\t]';comment='';quotes='';options='numeric';
[TDalldata, result]= readtext(filespec, delimiter, comment, quotes, options);
Num_trialstd=(length(TDalldata(1,:))-1)/68;
Program 2:
[fname fpath]=uigetfile('*.txt','Please select the _td file');
conditionid=input('Enter the condition (no spaces): ','s');
cd(fpath);
[dataALL,results]=readtext(fname,';','','','numeric');
[row, col]=find(dataALL(:,3)>0);
data=dataALL(row:length(dataALL),:);
What I am wondering is if there is a function I am unaware of that would automatically be able to distinguish the differences between text files?
If what i'm asking is unclear, I can provide clarification.
Thank you.
2 Commenti
Voss
il 21 Gen 2022
Is the idea is that you have a set of text files, each of which may have one format or another but you can't tell what the format is beforehand? If so, you may try something along the lines of:
try
read_file_method_1(file_name);
catch
read_file_method_2(file_name);
end
But you'd have to be sure that attempting to read any file with format 2 using method 1 will generate an error, i.e., you don't want to be able to "successfully" call read_file_method_1() on a file with format 2 and get nonsense results. You may have to do some sanity-check in read_file_method_1() that makes sure everything looks good and if not, throw an error to trigger the catch block, which will call read_file_method_2().
Is that more-or-less the situation here? If not, please explain more about what the situation is, and maybe attach a couple of sample text files.
Stuart Nezlek
il 24 Gen 2022
Risposta accettata
Più risposte (1)
Stuart Nezlek
il 2 Feb 2022
Modificato: Stuart Nezlek
il 2 Feb 2022
0 voti
Categorie
Scopri di più su Matrix Indexing in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!