Index in position 2 exceeds array bounds.
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Dyuman Joshi
2024-3-16
"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?
采纳的回答
Voss
2024-3-16
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)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!