필터 지우기
필터 지우기

how to add formatspec in writematrix

조회 수: 21 (최근 30일)
adhi dermawan
adhi dermawan 2023년 3월 21일
댓글: Rik 2023년 3월 21일
Dear matlab expert, I have these script
clc;clear; close all;
% Specify the folder where the files live.
myFolder = 'C:\ZTD\Wetz dan Dryz\DryZ\DryZ';
% Check to make sure that folder actually exists. Warn user if it doesn't.
if ~isfolder(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s\nPlease specify a new folder.', myFolder);
uiwait(warndlg(errorMessage));
myFolder = uigetdir(); % Ask for a new one.
if myFolder == 0
% User clicked Cancel
return;
end
end
Allfile = fullfile(myFolder, '*.txt'); % Change to whatever pattern you need.
List = dir(Allfile);
for k = 1 : length(List)
sites = List(k).name;
num = readmatrix(sites);
num(:,end)=[];
% % % sum up dryz+wetz in txt file
zwd1 = num(1:end,2);
zwd2 = num(1:end,3);
zwd3 = num(1:end,4);
% Seconds since 2000-01-01 00:00:00.0
time_sec2000 = num(1:end,1);
% % standard deviation values
% stdev = num(1:2:end,4);
% % mjd corresponding to 2000-01-01 00:00:00.0
mjd20000 = 51544;
% % Decimal days since 2000-01-01 00:00:00.0
time_days = time_sec2000/86400;
% % time vector in mjd
MJD = time_days + mjd20000;
% % compute decimal year
[year, month, day, hour, minute, second] = datevec(MJD + 678942);
% % time vector in decimal year
YYF = decyear([year, month, day, hour, minute, second]);
% PWV = zwd*0.15;
newdata = [MJD YYF zwd1 zwd2 zwd3];
% %save data
writematrix (newdata,sites,'Delimiter','space')
end
I want my output file have formatspec using fprintf with MJD %15.8f YYF %14.8f and zwd1,zwd2,zwd3 %18.16f and I want to change the output filename to filename_out using writematrix. How can I do it?
  댓글 수: 1
Rik
Rik 2023년 3월 21일
If you have a strong opinion on the formatting, why don't you use fprintf instead of writematrix?
(just remember that MatrixWithData(:) will go through your array column by column, while you will read your text file row by row)

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by