2016-10-11 3 views
0

matlab을 사용하여 텍스트 파일을 찾아로드하고 일부 커브를 표시 할 수있는 사용자 인터페이스를 개발 중입니다. 문제가 발생했습니다. 파일 텍스트는 십진수입니다. matlab은 그 수를 두 개의 열로 읽습니다. 그래서GUI matlab에서 십진수 읽기

[filename pathname] = uigetfile({'*.txt'},'File Selector'); 
fullpathname = strcat(pathname,filename); 
text = fileread(fullpathname); %reading information inside a file 
set(handles.text6,'string',fullpathname)%showing full path name 
set(handles.text7,'string',text)%showing information 
loaddata = fullfile(pathname,filename); 
xy = load(loaddata,'-ascii','%s'); 
t = xy(:,1); 
i = xy(:,3); 
handles.input1 = i; 
handles.input2 = t; 
axes(handles.axes1); 
plot(handles.input1,handles.input2) 

곡선 strenge 보이는, 그래서 결과를 확인 :이 코드를들이받은 후

enter image description here

: u는 여기에 내가 작업하고있는 파일을 찾을 수 : 이는 exemple입니다 명령 창을 사용하여 xy = load (loaddata, '- ascii') 여기에 문제가 나타납니다!

enter image description here

그래서 내가 대신 6의 지금 (12) 열이! 나 좀 도와 줄 수있어? strrep (데이터, ',', '.')를 시도했지만 작동하지 않습니다! 쉼표를 사용하고 있기 때문에

+1

파일 파싱에 대한 질문이 있으십니까? 어떨까요? * 실제 파일 내용을 게시하고 관련 코드 행만 표시하십시오. 이것은 GUI와 관련이 없습니다. – Suever

+0

안녕하세요, 제 질문을 편집하여 더 명확하게 확인해주세요 :) –

+0

스크린 샷을 게시하는 대신 질문에 실제 데이터를 붙여 넣을 수 있습니까? – Suever

답변

0

, 당신의 기점을 위해, 당신은 .,을 대체 문자열로 전체 파일의 첫 번째로드를 원할 것입니다 그리고 당신은 숫자 배열

에 전체 파일을 변환 할 수 str2num을 사용할 수 있습니다
% Read the entire file into memory 
fid = fopen(loaddata, 'rb'); 
contents = fread(fid, '*char')'; 
fclose(fid); 

% Replace `,` with `.` 
contents = strrep(contents, ',', '.'); 

% Now convert to numbers 
data = str2num(contents); 
+0

@EmnaAmeur 그게 효과가있다면 당신에게 해결책으로 표시하는 것을 고려해보십시오. – Suever