Clear Filters
Clear Filters

Read datas with different extension in a loop

1 view (last 30 days)
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 Comments
cemsi888
cemsi888 on 9 Feb 2015
Edited: Guillaume on 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 on 9 Feb 2015
Edited: Jan on 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.

Sign in to comment.

Accepted Answer

Jan
Jan on 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 Comments
cemsi888
cemsi888 on 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 on 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?

Sign in to comment.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!