Read datas with different extension in a loop

1 visualización (últimos 30 días)
cemsi888
cemsi888 el 9 de Feb. de 2015
Editada: Guillaume el 9 de Feb. de 2015
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 comentarios
cemsi888
cemsi888 el 9 de Feb. de 2015
Editada: Guillaume el 9 de Feb. de 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 el 9 de Feb. de 2015
Editada: Jan el 9 de Feb. de 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.

Iniciar sesión para comentar.

Respuesta aceptada

Jan
Jan el 9 de Feb. de 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 comentarios
cemsi888
cemsi888 el 9 de Feb. de 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 el 9 de Feb. de 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?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by