Help me to make my MATLAB code smarter to run
1 view (last 30 days)
Show older comments
I wrote a code to read and extract some parameter from a dataset at every hour. The import data is in a text file. The data file contains measurement records every 15 minutes for a day. My code works fine if the data record is complete. However, if a measurement at a particular time is missing, the code can not run. The attached files contain function script and two datasets:CPNFC20060102.txt (complete record) and KTBFC20120229.txt (uncomplete record). Kindly help and guide me to make this code smart to detect missing period and assign NaN values to the record.
- Entry for KTBFC 2012/02/29 00:15:00 is missing in KTBFC20120229.txt*
- The code is to read hourly values
Filename='CPNFC20060102.txt'; % runs fine
Data = importdata(Filename);
%
%Selecting cell Line every hour
for i=1:24;
for j=1;
FreqLine{j,i}=Data{(i-1)*64+10,1};
end
end
%
FreqLine=FreqLine';
% Spliting the cell to get character
for i=1:24
for j=1;
FreqCharLn(i,:)=FreqLine{i,j};
end
end
% Picking the parameter value of interest(foF2) from the dataset
for i=1:24
FreqStrg(i,:)=FreqCharLn(i,57:59);
end
% Convert string to number
FreqStrg(FreqStrg == ' ')='0' % replace empty spaces with zero
FreQ=str2num(FreqStrg) % Covert string to number
FreQ(FreQ==000)=nan; % Parameter is obatined
Answers (1)
See Also
Categories
Find more on Characters and Strings 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!