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!