How can I preallocate this script code to speed?

1 view (last 30 days)
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"

Answers (0)

Categories

Find more on Programming 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!