Read datas with different extension in a loop

1 visualizzazione (ultimi 30 giorni)
Hi i wrote code to read text files and it works properly.The Problem is from test device i get results with different ending. sometimes with '.*erg' sometimes another Option.I think that i should write a function and Combine with Loop. Could you recommend me something ? Thanks
  2 Commenti
cemsi888
cemsi888 il 9 Feb 2015
Modificato: Guillaume il 9 Feb 2015
I want to add this Kind of thing to read my files dynamically which have different extension.
clear all
clc
function einlesen= ergebnisfiles(i)
if ergebnisfiles(i)=dir('*.erg')
daten=fopen('ergebnisfiles(i)','r')
zeile = textscan(daten,formatSpec1,181,'delimiter',';','headerLines',4)
fclose(daten);
else if ergebnisfiles(i)=dir('*txt')
daten=fopen('ergebnisfiles(i)','r')
zeile = textscan(daten,formatSpec1,181,'delimiter',';','headerLines',4)
fclose(daten);
else ergebnisfiles(i)=dir('*pdf')
daten=fopen('ergebnisfiles(i)','r')
zeile = textscan(daten,formatSpec1,181,'delimiter',';','headerLines',4)
fclose(daten);
end
end
end
Jan
Jan il 9 Feb 2015
Modificato: Jan il 9 Feb 2015
Please format your code correctly to make it readable. You can edit the original question instead of hiding important information in a comment, where it vanishes as soon as some other comments are posted.
Omit the "clear all" to allow the usage of the debugger.

Accedi per commentare.

Risposta accettata

Jan
Jan il 9 Feb 2015
I do not understand the connection between your question and the code. But a comment:
for i=1:length(zeile{1,1})
tmp=zeile{1,1}{i}
tmp=strrep(tmp,'.','_dot')
zeile{1,1}(i)=cellstr(tmp);
end
Smarter without a loop:
zeile{1} = strrep(zeile{1}, '.', '_dot');
  2 Commenti
cemsi888
cemsi888 il 9 Feb 2015
function einlesen= ergebnisfiles(i)
ergebnisfiles={};
if ergebnisfiles(i)=dir('*.erg')
daten=fopen('ergebnisfiles(i)','r')
einlesen = textscan(daten,formatSpec1,181,'delimiter',';','headerLines',4)
fclose(daten);
else if ergebnisfiles(i)=dir('*.txt')
daten=fopen('ergebnisfiles(i)','r')
zeile = textscan(daten,formatSpec1,181,'delimiter',';','headerLines',4)
fclose(daten);
else ergebnisfiles(i)=dir('*.pdf')
daten=fopen('ergebnisfiles(i)','r')
zeile = textscan(daten,formatSpec1,181,'delimiter',';','headerLines',4)
fclose(daten);
end
end
end
cemsi888
cemsi888 il 9 Feb 2015
Forget what i wrote before :D it was my whole script.i want to write a function read files from different pfad. My first question is: The script that i wrote and sent unfortunately does not work. 2) i want to create gui and thats why i will work with Buttons.i want to create "open" button to choose my Experiment files from different pfad. any advices for These two questions?

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Environment and Settings in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by