how to export of a sub aera of an array to xyz?

5 views (last 30 days)
if I use:
F = scatteredInterpolant(x,y,z,'natural','none');
xv=linspace(min(x,[],'all'),max(x,[],'all'),(max(x)-min(x))/faktor);
yv=linspace(min(y,[],'all'),max(y,[],'all'),(max(y)-min(y))/faktor);
zg = F({xv,yv});
and want to export an area of this array:
A=xv(1600:1:2000);
B=yv(400:1:800);
C = F({A,B});
to an xyz file....how can I manage this?
This:
fid = fopen('vdo.txt','w') ;
fprintf(fid,'%f %f %f\n', A', B', C') ;
fclose(fid) ;
or that
xx = A(:) ;
yy = B(:) ;
zz = C(:) ;
P = [xx yy zz] ;
fid = fopen('cut.dat', 'wt');
fprintf(fid, [repmat('%f\t', 1, size(P,2)-1) '%f\n'],P.');
fclose(fid)
doesn't work...
Thanks a lot

Accepted Answer

KSSV
KSSV on 28 May 2022
Edited: KSSV on 28 May 2022
xx = A(:) ;
yy = B(:) ;
zz = C(:) ;
P = [xx yy zz] ;
fid = fopen('test.txt','w')
fprintf(fid,'%f %f %f\n', P.') ;
fclose(fid)
  5 Comments
KSSV
KSSV on 28 May 2022
In that case, obviously you will get error. Becuase your xx,yy is 401*1 and zz is 160801*1; which you cannot merge into a column matrix. Try this:
[A,B] = meshgrid(A,B) ;
xx = A(:) ;
yy = B(:) ;
zz = C(:) ;
P = [xx yy zz] ;
fid = fopen('test.txt','w')
fprintf(fid,'%f %f %f\n', P.') ;
fclose(fid)
Harald von der Osten
Harald von der Osten on 28 May 2022
ha!! It works ! Thank you very much for your help, dear KSSV

Sign in to comment.

More Answers (0)

Categories

Find more on Shifting and Sorting Matrices in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!