Help me to make my MATLAB code smarter to run
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Stephen23
el 14 de Feb. de 2017
"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.
Respuestas (1)
Saeed Bello
el 15 de Feb. de 2017
Editada: Saeed Bello
el 15 de Feb. de 2017
2 comentarios
Stephen23
el 15 de Feb. de 2017
@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.
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!