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
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?
Yat Chi
Yat Chi 2024-3-16
Ok understand what you mean but just to know if there is a more automatic method to delete rows. The making a table and storing it in cell elements is for other section of the code. Anyway thanks for your help.

请先登录,再进行评论。

采纳的回答

Voss
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)
PrJ_2 = 33×1795
3.0000 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 4.0000 NaN NaN NaN NaN 136.1970 130.8706 141.1751 143.1207 144.7861 -3.4082 0.7591 6.7263 6.4537 6.5266 7.2149 4.9448 10.1725 18.7580 18.9680 16.2203 25.2269 18.6414 28.8863 25.6769 NaN 23.8822 18.6764 19.5069 10.4615 8.0000 NaN NaN NaN NaN 169.0315 166.3296 167.2861 166.5495 165.8922 -10.3660 -9.3330 -7.9190 -6.4407 -10.2092 -10.6448 -10.3631 -10.0301 -8.9738 -8.7434 -10.5318 -1.7179 -15.0213 -1.8544 -2.0730 -2.5019 -6.1642 -8.2347 -9.3253 -10.0257 16.0000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 26.0000 -69.0541 -197.6579 -57.9101 -62.9209 -67.2867 -65.2820 -63.5763 -63.2911 -63.8459 2.1932 0.2411 1.9270 4.2713 5.1771 6.4027 2.9323 1.5595 1.7470 3.4932 2.2814 8.9242 -3.2796 8.8592 9.6653 7.8349 3.3257 1.5553 1.0630 3.2883 27.0000 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 28.0000 -47.7252 -124.3292 -40.4868 -41.7452 -42.6135 -42.8523 -41.8311 -41.9533 -44.4137 -4.5481 -2.9884 -0.4678 -0.8905 -1.5449 -1.5456 -3.6049 -4.1030 -3.9603 -3.4202 -4.3380 3.2208 -8.0708 6.7611 3.9822 5.7636 1.5892 -0.7280 -0.2669 -0.3680 29.0000 NaN NaN NaN NaN -120.6057 -120.5668 -118.3917 -118.3361 -119.7252 -0.3101 -1.5797 1.9871 10.6468 11.6253 3.5880 NaN NaN NaN NaN NaN NaN NaN NaN 1.4403 2.4198 0.9959 -1.2894 -1.4145 -3.9660 31.0000 -27.6366 -42.6817 -12.7390 -13.2953 -14.9591 -15.3957 -15.7503 -14.2491 -15.0859 0.0452 2.0676 3.8311 2.0755 3.4006 2.9644 2.0100 1.6939 1.7602 1.3049 -0.8883 7.4725 -7.7919 6.1037 5.9680 6.4941 2.8828 -0.6491 0.6761 -0.3384 32.0000 -162.6105 -455.0805 -148.2504 -149.8512 -151.6037 -151.9213 -151.2793 -151.7869 -153.1546 -13.2760 -11.5371 -9.7379 -9.4090 -6.5996 -5.5685 -5.3775 -6.3775 -5.1962 -4.5600 -4.7826 1.3573 -14.6563 -2.7435 -2.1541 -2.7174 -3.8562 -7.0394 -6.8641 -6.0562
  2 个评论
Yat Chi
Yat Chi 2024-3-18
Thanks for your help, this becomes better now. Sorry for late peply as I am busy these days. Thanks again

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品


版本

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by