Index exceeds matrix dimensions
이전 댓글 표시
Index exceeds matrix dimensions.
Error in tvf_emd (line 47)
y = [fliplr(y(2:2+num_padding-1)) y fliplr(y(end-num_padding:end-1))]; % padding to deal with boundary effect (symmetric).
trying to solve this problem in my code but im finding it difficult. Please can anyone help solve this problem for me. its urgent as I need to complete my paper.
attached are the codes and data used.
답변 (2개)
Walter Roberson
2019년 9월 17일
num_padding = round(length(temp_x)*0.5);% padding number
length is defined as:
temp = size(TheInput)
if any(temp == 0)
length is 0 no matter what the other dimensions are
else
length is max(temp)
end
length is not any particular dimension: for a matrix that is not empty, length is the largest dimension.
You then use effectively go row by row through temp_x, with the rows being length 231, which is less than num_padding, so using num_padding exceeds the end of the row.
댓글 수: 7
Yussif M. Awelisah
2019년 9월 17일
Walter Roberson
2019년 9월 17일
The definition of length that I gave is pseudocode, not MATLAB code.
You need to change
num_padding = round(length(temp_x)*0.5);% padding number
to one of
num_padding = round(size(temp_x,1)*0.5);% padding number
or
num_padding = round(size(temp_x,2)*0.5);% padding number
At the moment I do not have time to figure out which of the two is appropriate for you.
Yussif M. Awelisah
2019년 9월 18일
Walter Roberson
2019년 9월 18일
You removed the "for" loop on y, so now you are deriving y from y = temp_x which is a 2D array. But your line
y = [fliplr(y(2:2+num_padding-1)) y fliplr(y(end-num_padding:end-1))]; % padding to deal with boundary effect (symmetric)
indexes y with a single index, which often implies that you are thinking of it as a vector rather than a 2D array (it is permitted to index a 2D array with a single index, and there are some very good reasons to do so, but you need to be careful with it.)
With y being a 2D array, when you index it with a vector, the result is going to be a column vector. You fliplr() the column vector, which leaves it unchanged. (In your previous version with the for y, y would have been a column vector instead of 2D, so the fliplr() would have been wrong for it too.) For column vectors you would want to use flipud()
You take that column vector and try to horzcat() it with the full 2D y array. That can only work if the extracted column vector has exactly the same number of rows as y has, which it will not have. You also have the fliplr() issue at the end of the line as y(end....) is again a single index into a 2D array and that is going to return a column vector.
If you somehow were managing to match the number of rows in the parts, then you would be horzcat a single column, then a 2D array, then a single column, and the result would be a 2D array that had 2 more columns than the original array. It is not obvious that would be your intention.
Yussif M. Awelisah
2019년 9월 18일
Walter Roberson
2019년 9월 18일
Using length() is always wrong for this purpose.
Walter Roberson
2019년 9월 18일
I am not clear as to why you removed the for y loop ?
The code does not have enough documentation for me to understand what you want to do.
Did you remove the for y loop in an attempt to vectorize the calculations?
tt=1:numel(y);
ind_remov_pad=num_padding+1:numel(y)-num_paddi
That code is wrong for 2D arrays y.
It looks to me as if the best way to proceed would be to use a for loop whose indices were the row numbers of temp_x, and inside the loop,
y = temp_x(row_number, :);
After which you do the padding and so on.
Yussif M. Awelisah
2019년 9월 18일
0 개 추천
댓글 수: 3
Walter Roberson
2019년 9월 18일
It looks to me as if the best way to proceed would be to use a for loop whose indices were the row numbers of temp_x, and inside the loop,
y = temp_x(row_number, :);
After which you do the padding and so on.
As in
for row_number = 1 : size(temp_x,1)
y = temp_x(row_number, :);
y = [fliplr(y(2:2+num_padding-1)) y fliplr(y(end-num_padding:end-1))]; % padding to deal with boundary effect (symmetric)
....
end
Yussif M. Awelisah
2019년 9월 20일
Yussif M. Awelisah
2019년 9월 23일
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!