changes and errors in a programm

1 view (last 30 days)
rania
rania on 18 Jul 2013
I have attachead a programm with which I have to take some results by inserting inputs. My inputs contain measurements like "mm dd yyy" for consecutive days (e.g. 03012013_03062013). This function reads the ascci files and makes singe day hourly avereged size distribution ascci files in the directory results. Firstly, I want to change the name of the files that are created. I want them "mmddyyyy" because now they are named "mdyyyy". Secondly, there is always an error in the first day because it contains some measurements of the second day too. We want hours from 0 to 23 and if one day starts from a different hour-number except 0, data stops when 24hours are completed and so it contains some data from the next day. I really need your help because I only know a few things in programming and I must complete this work. If I was not very enlightening please ask me more questions.(there are comments in the programm that will may also help). I use matlab 7.9.0(R2009b)
function make_perday_discrim_grimm
% Import the ascii data exported by dust monitor in an excel sheet and meke % the first column mm/dd/yyyy hh:mm:ss. % Import the exported from excel txt into an ascii file. Delete the first % two lines (header) % With a proffessional text editor replace int this ascii the following % / with " " and : " "
%This function reads the ascci and make singe day hourly avereged size dist. ascci files in the directory results
% The input window opens in order to select the appropriate ozone signals. [fileToRead1, pathname]=uigetfile({'*.txt'},'Import Grimm ascii Files', 'MultiSelect', 'off'); %if user cancels save command, nothing happens if isequal(fileToRead1,0) isequal(pathname,0) return end
addpath(pathname);
rawData1 = importdata(fileToRead1);
[~,name] = fileparts(fileToRead1); newData1.(genvarname(name)) = rawData1;
assignin('base', 'A', rawData1);
A=evalin('base', 'A');
days = A(:,1:3); [b_days bb_days J_days] = unique(days,'rows');
kk=ones(1, length(b_days)); for i=1:1:length(b_days) filename=[num2str(b_days(i,1)) num2str(b_days(i,2)) num2str(b_days(i,3))]; kk(i)=str2num(filename); end kk=kk'; filename=num2str(kk);
export_data=struct; for i=2:1:length(kk); export_data(1).dat=A(1:bb_days(2)-bb_days(1),:); export_data(i).dat=A((bb_days(i-1)+1):(bb_days(i)),:); end
initial=pwd; cd('./results/perday'); for i=1:1:length(kk); files_export = export_data(1,i).dat(:,:); filename_exp=filename(i,:); % header_1={'Month', 'Day', 'Year', 'HH', 'MM', 'SS','particle/m3/sizebin', 'particle/m3', 'particle/m3', 'particle/m3', 'particle/m3', 'particle/m3', 'particle/m3','particle/m3', 'particle/m3', 'particle/m3', 'particle/m3/sizebin', 'particle/m3', 'particle/m3', 'particle/m3', 'particle/m3', 'particle/m3', 'particle/m3','particle/m3', 'particle/m3', 'particle/m3', 'particle/m3/sizebin', 'particle/m3', 'particle/m3', 'particle/m3', 'particle/m3', 'particle/m3', 'particle/m3','particle/m3', 'particle/m3', 'particle/m3'} ; % header_1={'Month', 'Day', 'Year', 'Time', 'particle/m3/sizebin', 'particle/m3'} ; %trick to write strings as formated in a text box etc % header_1=header_1.'; % txt=sprintf([repmat('%s\t',1,size(header_1,1)),'\n'],header_1{:}); % dlmwrite(filename_exp,txt,''); %now open the file again -a append and write everything else you want fid = fopen([filename_exp],'a'); fprintf(fid, '%2.0f %2.0f %4.0f %2.0f %2.0f %2.0f %8.0f %8.0f %8.0f %8.0f %8.0f %8.0f %8.0f %8.0f %8.0f %8.0f %8.0f %8.0f %8.0f %8.0f %8.0f %8.0f %8.0f %8.0f %8.0f %8.0f %8.0f %8.0f %8.0f %8.0f %8.0f %8.0f %8.0f %8.0f %8.0f %8.0f %8.0f\n', [files_export']); % fprintf(fid, '%2.0f %2.0f %4.0f %2.0f %8.0f %8.6f\n', [files_export']); fclose(fid); end cd(initial);
end

Answers (0)

Categories

Find more on Data Type Conversion 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!