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!