Read datas with different extension in a loop

1 次查看(过去 30 天)
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 个评论
cemsi888
cemsi888 2015-2-9
编辑:Guillaume 2015-2-9
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 2015-2-9
编辑:Jan 2015-2-9
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.

请先登录,再进行评论。

采纳的回答

Jan
Jan 2015-2-9
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 个评论
cemsi888
cemsi888 2015-2-9
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 2015-2-9
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?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by