필터 지우기
필터 지우기

Read datas with different extension in a loop

조회 수: 1 (최근 30일)
cemsi888
cemsi888 2015년 2월 9일
편집: Guillaume 2015년 2월 9일
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