MATLAB Answers

How can I preallocate this script code to speed?

2 views (last 30 days)
Eman Saleem
Eman Saleem on 2 Jul 2019
Edited: Eman Saleem on 2 Jul 2019
How can I preallocate this script code to speed?
%get GPS/MEAS lines
clc
clear ALL
File_ID_1 =fopen('C:\Users\Eman Abdelrazeq\Desktop\gLAB documments\gLab function\dataMO_ME.out');
if File_ID_1< 0
fprintf('File does not exist')
end
ind=0;
%MEAS_MATRIX=ones(31917,9);
for i=1:239522
line_MEAS=fgets(File_ID_1);
if line_MEAS(1:4)=="MEAS" && line_MEAS(29:31)=="GPS"
ind=ind+1;
YEAR(ind,1)=str2double(line_MEAS(11:14));
DAY(ind,2)=str2double(line_MEAS(16:18));
SECOND(ind,3) =str2double(line_MEAS(20:27));
PRN(ind,4)=str2double(line_MEAS(33:34));
ELEVATION(ind,5)=str2double(line_MEAS(38:43));
AZMUTH(ind,6) =str2double(line_MEAS(45:52));
C1C(ind,7)=str2double(line_MEAS(107:119));
C1P(ind,8)=str2double(line_MEAS(137:149));
C2P(ind,9)=str2double(line_MEAS(167:179));
MEAS_MATRIX(ind,1)=YEAR(ind,1);
MEAS_MATRIX(ind,2)=DAY(ind,2);
MEAS_MATRIX(ind,3)= SECOND(ind,3);
MEAS_MATRIX(ind,4)= PRN(ind,4);
MEAS_MATRIX(ind,5)= ELEVATION(ind,5);
MEAS_MATRIX(ind,6)= AZMUTH(ind,6);
MEAS_MATRIX(ind,7) = C1C(ind,7);
MEAS_MATRIX(ind,8)= C1P(ind,8);
MEAS_MATRIX(ind,9)=C2P(ind,9);
end
end
fclose( File_ID_1);
Also why if I add (while ~feof(File_ID_1) At the begining befor ( for loop) it give me this error
Index exceeds the number of array elements (1).
Error in MEAS_DATA (line 20)
if line_MEAS(1:4)=="MEAS" && line_MEAS(29:31)=="GPS"

  1 Comment

dpb
dpb on 2 Jul 2019
Use the fixedwidth import options object with readtable...

Sign in to comment.

Answers (0)