How can I add data to an existing array when the dimension do not agree?

1 visualización (últimos 30 días)
How can I add to an existing array that has dimensions (1,80) when the line of data that I need to add is (1,161)? I keeping getting a size error. What I'm trying to do is use fgetl to read a RINEX file and store the data from it. The data in the first line is shorter then the 2nd line. After the first line the data characters remain constant so I just need to figure out how to size up the matrix without deleting the 1st line of data. datagps is the variable im using to store the data.
gps = 0;
if (txtLine(1) == 'G')
gps = gps + 1
dataGPS(gps,:) = txtLine % 1st line is 80 char
for nLine = 1:noLinesGPS
gps = gps + 1
txtLine = fgetl(fid_temp);
dataGPS(gps,:) = sprintf('%s %s', dataGPS, txtLine); % 2nd line and all proceeding lines are 161 char
% C1 = numel(dataGPS)
% GP = (C1:gps)
% GP(gps,1)= dataGPS
end
end

Respuesta aceptada

Stephen23
Stephen23 el 16 de Jul. de 2020
Editada: Stephen23 el 16 de Jul. de 2020
Just use indexing to specify how many elements you are allocating to. MATLAB will expand the array to fit:
>> B = ['ABC';'DEF']
B =
ABC
DEF
>> B(3,1:5) = 'Hello'
B =
ABC
DEF
Hello
For best results you should preallocate the array before the loop, or even just an empy array with the final number of columns.

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays 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!

Translated by