Index in position 2 exceeds array bounds.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Yat Chi
el 16 de Mzo. de 2024
Comentada: Voss
el 18 de Mzo. de 2024
I have written a code to rearrange the pseudorange error of each satellite during the experiment, which the code runs well without any problem. However, when a new experiment is done, this section of code is having problems with comment: Index in position 2 exceeds array bounds.
Where I find is some rows in the variable Pr_error_2 seems to have no data, causing when the code is looping, error happens. But how can I delete all the rows that without data inside? I tried rmmissing but seems not working. Thanks for your help.
Here is the code:
Pr_error_2 = Pr_error;
Pr_error_2(:,2) = [];
for k = 1:t % numel(Pr_error_2)
PrT{k} = array2table(Pr_error_2{k}(:,[1 2]), 'VariableNames',{'Satellite',sprintf('Error_%04d',k)});
end
PrJ = PrT{1};
for k = 1:numel(PrT)-1
PrJ = outerjoin(PrJ,PrT{k+1},'Keys',1, 'MergeKeys',1);
end
PrJ_2 = PrJ;
PrJ_2 = table2array(PrJ_2);
2 comentarios
Dyuman Joshi
el 16 de Mzo. de 2024
"But how can I delete all the rows that without data inside?"
Check whether the contents of that cell are empty or not, and then delete accordingly.
"I tried rmmissing but seems not working."
Yes, because the missing element in a cell array is defined as {''} i.e. it only works on a cell array of char vectors, see here - https://in.mathworks.com/help/matlab/ref/rmmissing.html#description
I don't understand what exactly are you doing here - Why are you making a table and storing it in cell elements?
Respuesta aceptada
Voss
el 16 de Mzo. de 2024
load Pr_error_2
"how can I delete all the rows that without data inside?"
Like this:
empty_idx = cellfun(@isempty,Pr_error_2);
Pr_error_2(empty_idx) = [];
Then the loops run fine:
PrT = cell(1,numel(Pr_error_2)); % pre-allocate PrT
for k = 1:numel(Pr_error_2)
PrT{k} = array2table(Pr_error_2{k}(:,[1 2]), 'VariableNames',{'Satellite',sprintf('Error_%04d',k)});
end
PrJ = PrT{1};
for k = 1:numel(PrT)-1
PrJ = outerjoin(PrJ,PrT{k+1},'Keys',1, 'MergeKeys',1);
end
PrJ_2 = table2array(PrJ)
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements 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!