Text Output to File
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!