필터 지우기
필터 지우기

Text Output to File

조회 수: 3 (최근 30일)
Amanda
Amanda 2013년 2월 12일
Trying to achieve an output to a textfile as seen below:
x1 y1 series
1 1 174.08
2 1 174.08
3 1 174.08
4 1 174.08
5 1 174.08
Instead I'm getting:
x1 y1 series
1 2 3
4 5 1
1 1 1
1 174.085
Here is my code:
x1 = [1 2 3 4 5];
y1 = [1 1 1 1 1];
handles = [];
fid = fopen('filename.txt','w+')
g1 = plot(x,y)
h1 = findobj(g1,'Type','line')
x = get(h1,'xdata')
y = get(h1,'ydata')
axis equal;
handles(1) = h1;
set(g1,'ButtonDownFcn',{@ButtonClick,h1});
fprintf(fid,'%s\t %s\t %s\n', 'x1', ' y1','series');
fprintf(fid,'%g\t %g\t %f\n' ,x, y, h1);
fclose(fid)
Thanks, Amanda

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 2월 12일
x1 = [1 2 3 4 5];
y1 = [1 1 1 1 1];
handles = [];
fid = fopen('filename.txt','w+')
g1 = plot(x1,y1)
h1 = findobj(g1,'Type','line')
x = get(h1,'xdata')
y = get(h1,'ydata')
xy=[x; y; repmat(h1,1,numel(x))]
axis equal;
handles(1) = h1;
set(g1,'ButtonDownFcn',{@ButtonClick,h1});
fprintf(fid,'%s\t %s\t %s\n', 'x1', ' y1','series');
fprintf(fid,'%g\t %g\t %f\n' ,xy);
fclose(fid)
  댓글 수: 1
Amanda
Amanda 2013년 2월 12일
Thanks a lot.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2013년 2월 12일
fprintf(fid,'%g\t %g\t %f\n', [x; y; h1]);

카테고리

Help CenterFile Exchange에서 Language Fundamentals에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by