Sequential file save/output
4 views (last 30 days)
Show older comments
I am reading multiple txt files in sequence (one at a time) and modifying the data by interpolating over nan values and then I want to write to the same file name, but adding an extension (such as .xyz) at the end of each original file name so that I know which files were modified. I am not sure whether to use dlmwrite, save, or sprintf?
Here is what I have so far:
fprintf('reading in tXYsb data from text files...\n\n') c = dir('*.txt'); d=length(c);
for q = 1:d
%ICPdata = []; for n = 1:numel(c) fid = fopen(c(n).name); ICPdata = textscan(fid,'%f %f %f %f %f');
[pathstr,name,ext]=fileparts(c(n).name);
% ICPdata = [ICPdata; ICPdata_new];
ICPdata = cell2mat(ICPdata); % gets rid of cells in following code
ICP_t = ICPdata(:,1); %2000 time (sec) ICP_x = ICPdata(:,2); % x position (ps71) ICP_y = ICPdata(:,3); % y position (ps71) ICP_s = ICPdata(:,4); %surface elev ICP_b = ICPdata(:,5); %bed elev
fclose(fid);
ICP_data_array = [ICP_t, ICP_x, ICP_y, ICP_s, ICP_b];
ICP_xi=fixgaps(ICP_x); ICP_yi=fixgaps(ICP_y); ICP_si=fixgaps(ICP_s); ICP_bi=fixgaps(ICP_b);
Interp_ICP_radar_data = [ICP_t, ICP_xi, ICP_yi, ICP_si, ICP_bi];
% export data
fprintf('writing tXYsb data to text file...\n\n') save([name.xyz Interp_ICP_radar_data '.txt'],'-ascii','-tabs'); % dlmwrite(name '.text',Interp_ICP_radar_data,'delimiter','\t','precision','%10.3f') % filename = sprintf(name.xyz, x); % dlmwrite(Interp_ICP_radar_data, filename);
fprintf('finished.\n')
end
end
0 Comments
Answers (0)
See Also
Categories
Find more on Data Import and Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!