Someone can explain to me how to generate and save a txt, excel file data, after "for loop" and is meshgrid ?
5 次查看(过去 30 天)
显示 更早的评论
Hi,
I have the following script to run the attached data.
fname1 = uigetfile({'*.txt;*.dat;*.tab','Data Files (*.txt,*.dat,*.tab)'; '*.*','All Files (*.*)'},'Ficheiro de dados da Pangaea');
[name,latitude,longitude,depth,agemodel] = textread(fname1,'%s %f %f %f %f','headerlines',1);
agemodel2 = abs(agemodel-20)
LLDA = [latitude,longitude,depth,agemodel,agemodel2]; % Matriz
LLDAn = LLDA(:,1:5); %LLDA(:,2:5)
LLDAm = LLDAn;% cell2mat(LLDAn)
[LatUq, iL, iU] = unique(LLDAm(:,1));
[LonUq, iL, iU] = unique(LLDAm(:,2));
idade_int = zeros(numel(LatUq),numel(LonUq)) * NaN;
for n=1:numel(LonUq)
for m = 1:numel(LatUq)
ind = find(LLDAm(:,2) == LonUq(n) & LLDAm(:,1) == LatUq(m));
if (isempty(ind)), continue; end
%idade_int(n,m) = interp1([0; agemodel(ind)],[0; depth(ind)],20,'linear','extrap');
p = polyfit([0; agemodel(ind)],[0; depth(ind)], 1);
idade_int(m,n) = polyval(p, 20);
end
end
[lon,lat] = meshgrid(LonUq,LatUq)
Is that my results are the following: (for exemple)
lon1 lon2 lon3
lat1 NAN 1 NAN
lat2 NAN NAN 2
lat3 2 NAN NAN
Someone explain to me how to generate and save a txt, excel file data in the following way:
LongUq, LatUq, idade_int
??
Thank you very much Nuno Simões
3 个评论
回答(1 个)
Lee Albacker
2014-4-22
Assuming you want to concatenate the arrays (I'll also assume you can add your own headers if you want):
output = [LongUq, LatUq, idade_int];
To write to an xcell file: xlswrite('FILENAME.xlsx', output); file ends up in your current matlab path
To write to a text file that's tab delimited: dlmwrite('FILENAME.txt', output, 'delimiter', '\t', 'precision', NUMBER OF DECIMAL PLACES)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!