フィルターのクリア

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 Center および File ExchangeLanguage Fundamentals についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by