Help me to make my MATLAB code smarter to run
2 次查看(过去 30 天)
显示 更早的评论
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
2 个评论
Stephen23
2017-2-14
"make my MATLAB code smarter to run"
The best thing you could do is get rid of all of those numbered variables, and learn to use indexing.
That would make your code much simpler, and therefore neater, easier to read, easier to understand, and therefore easier to write and bugfix.
回答(1 个)
Saeed Bello
2017-2-15
编辑:Saeed Bello
2017-2-15
2 个评论
Stephen23
2017-2-15
@Saeed Bello: does this really answer to your own question? Or are you asking for more help? Why did you accept your own "answer" if it is not an answer? Accepting an answer tells people that your question has been resolved, and that you do not need further help.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!