MATLAB Answers

0

save data from file to matrix

Asked by Eman Saleem on 1 Jul 2019
Latest activity Commented on by Eman Saleem on 2 Jul 2019
Hi
I have raw data on a notepad++ file I want to select from the data and save it as matrix variable in the workplace
  • (sample of the data in the file)
MODEL 2019 056 0.00 GPS 27 C5X 0.07668 23011653.2030 23011649.6760 22308583.6676 10015468.5256 10633695.3749 899.6394 1023.9342
MEAS 2019 056 0.00 GPS 1 22.612 -40.542 12 C1C:L1C:C1P:L1P:C2P:L2P:C5X:L5X:C7X:L7X:C8X:L8X 23265359.6800 0.0000 0.0000
MEAS 2019 056 0.00 GPS 11 13.915 -26.326 12 C1C:L1C:C1P:L1P:C2P:L2P:C5X:L5X:C7X:L7X:C8X:L8X 24139174.5940 0.0000 0.0000
MODEL 2019 056 0.00 GPS 27 L1P 0.07668 23011645.8683 23011641.4197 22308583.6676 10015468.5256 10633695.3749 899.6394 1023.9342
MODEL 2019 056 0.00 GPS 27 C1C 0.07668 23011645.8590 23011647.2123 22308583.6676 10015468.5256 10633695.3749 899.6394 1023.9342
I want to choose the whole row of (MEAS) and save it as matrix.
I write the following code
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
for i=1:500
line_MEAS=fgets(File_ID_1);
if line_MEAS(1:4)=="MEAS"&& line_MEAS(29:31)=="GPS"
MEAS=convertCharsToStrings(line_MEAS(1:4));
YEAR=convertCharsToStrings(line_MEAS(11:14));
DAY=convertCharsToStrings(line_MEAS(16:18));
SECOND =convertCharsToStrings(line_MEAS(20:27));
GPS=convertCharsToStrings(line_MEAS(29:31));
PRN=convertCharsToStrings(line_MEAS(33:34));
ELEVATION=convertCharsToStrings(line_MEAS(38:43));
AZMUTH =convertCharsToStrings(line_MEAS(46:52));
C1C=convertCharsToStrings(line_MEAS(107:119));
C1P=convertCharsToStrings(line_MEAS(137:149));
C2P=convertCharsToStrings(line_MEAS(167:179));
MEAS_MATRIX(i,1)=MEAS;
MEAS_MATRIX(i,2)=YEAR;
MEAS_MATRIX(i,3)=DAY;
MEAS_MATRIX(i,4)=SECOND;
MEAS_MATRIX(i,5)=GPS;
MEAS_MATRIX(i,6)=PRN;
MEAS_MATRIX(i,7)=ELEVATION;
MEAS_MATRIX(i,8)=AZMUTH;
MEAS_MATRIX(i,9)=C1C;
MEAS_MATRIX(i,10)=C1P;
MEAS_MATRIX(i,11)=C2P;
end
end
This code give me the following
"MEAS" "2019" "056" " 0.00" "GPS" "22" "74.738" "-39.831" "20521198.3200" " 0.0000" "20521200.4960"
<missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing>
"MEAS" "2019" "056" " 0.00" "GPS" " 8" "24.647" " 13.860" "23389845.6330" " 0.0000" "23389854.0040"
"MEAS" "2019" "056" " 0.00" "GPS" "16" "63.481" "133.495" "20992641.6330" " 0.0000" "20992644.8590"
<missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing>
It gives the MEAS rows but Why the rows <missing>????

  0 Comments

Sign in to comment.

1 Answer

Answer by Geoff Hayes
on 2 Jul 2019

Eman - doesn't the empty rows make sense given that you only insert a row if
for i=1:500
line_MEAS=fgets(File_ID_1);
if line_MEAS(1:4)=="MEAS"&& line_MEAS(29:31)=="GPS"
% do stuff
% insert row
MEAS_MATRIX(i,1)=MEAS;
MEAS_MATRIX(i,2)=YEAR;
MEAS_MATRIX(i,3)=DAY;
MEAS_MATRIX(i,4)=SECOND;
MEAS_MATRIX(i,5)=GPS;
MEAS_MATRIX(i,6)=PRN;
MEAS_MATRIX(i,7)=ELEVATION;
MEAS_MATRIX(i,8)=AZMUTH;
MEAS_MATRIX(i,9)=C1C;
MEAS_MATRIX(i,10)=C1P;
MEAS_MATRIX(i,11)=C2P;
end
end
the condition is satisfied? And you use i to insert those rows into MEAS_MATRIX. So if the condition is not satisfied for a particular row, then that row will still exist in the matrix...but contain whatever default values were assigned to it when the matrix was created. If you don't want to inclue missing rows in your matrix, then use a different parameter to insert the rows into MEAS_MATRIX. For example,
j = 1;
for i=1:500
line_MEAS=fgets(File_ID_1);
if line_MEAS(1:4)=="MEAS"&& line_MEAS(29:31)=="GPS"
% do stuff
% insert row
MEAS_MATRIX(j,1)=MEAS;
MEAS_MATRIX(j,2)=YEAR;
MEAS_MATRIX(j,3)=DAY;
MEAS_MATRIX(j,4)=SECOND;
MEAS_MATRIX(j,5)=GPS;
MEAS_MATRIX(j,6)=PRN;
MEAS_MATRIX(j,7)=ELEVATION;
MEAS_MATRIX(j,8)=AZMUTH;
MEAS_MATRIX(j,9)=C1C;
MEAS_MATRIX(j,10)=C1P;
MEAS_MATRIX(j,11)=C2P;
j = j + 1;
end
end

  1 Comment

THANKS ALOT, IT WORKS .

Sign in to comment.