Save multiple variables into single -Ascii File with different column of [x:y:z]
21 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
MAT NIZAM UTI
el 21 de Mzo. de 2023
Comentada: MAT NIZAM UTI
el 23 de Mzo. de 2023
Hi, I want to save the variables into 3 column in a single .ascii file.
The dimension of each variables are same which is
SSS (102600x1)
Lat (102600x1)
Lon (102600x1)
I want to save into X:Y:Z matrix, where X=Lat, Y=Lon, Z=SSS in one single file of .ascii
Here I attach my coding, the problem is when I run this code, the 20150131.asc is not arrange into X:Y:Z, instead only one column, I believed there is problem in the code of save.
clear all
clc
ncfile = 'SM_REPR_MIR_OSUDP2_20150131T230416_20150131T235723_700_200_1.nc' ; % nc file name
% To get information about the nc file
ncinfo(ncfile)
% % to display nc file
ncdisp(ncfile)
% % to read a vriable 'var' exisiting in nc file
SSS = ncread(ncfile,'SSS_corr') ;
Lat = ncread(ncfile, 'Latitude');
Lon = ncread(ncfile, 'Longitude');
save('20150131.asc','SSS','Lat','Lon','-ASCII');
0 comentarios
Respuesta aceptada
Rik
el 22 de Mzo. de 2023
Editada: Rik
el 22 de Mzo. de 2023
Either use writematrix, or use fprintf. See the documentation for examples.
If you use fprintf, be aware that it will go through an array column by column, but you read a file row by row.
Edit: here are examples for both.
SSS = rand(10,1);
Lat = rand(10,1)+1;
Lon = rand(10,1)+2;
writematrix([SSS Lat Lon],'test.txt');
type test.txt
fid = fopen('test2.txt','w');
fprintf(fid,'%.1f %.1f %.1f\n',[SSS,Lat,Lon].');
fclose(fid);
type test2.txt
3 comentarios
Rik
el 22 de Mzo. de 2023
I have edited my answer, but the documentation pages for both functions also contain examples. You should really try to adapt those. That will help you solve your question without having to wait for us to respond.
Más respuestas (1)
Walter Roberson
el 22 de Mzo. de 2023
out = [SSS, Lat, Lon];
save('20150131.asc', 'out', '-ascii')
0 comentarios
Ver también
Categorías
Más información sobre Structures 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!