Text Output to File

1 visualización (últimos 30 días)
Amanda
Amanda el 12 de Feb. de 2013
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

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 12 de Feb. de 2013
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 comentario
Amanda
Amanda el 12 de Feb. de 2013
Thanks a lot.

Iniciar sesión para comentar.

Más respuestas (1)

Walter Roberson
Walter Roberson el 12 de Feb. de 2013
fprintf(fid,'%g\t %g\t %f\n', [x; y; h1]);

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by