Error using horzcat Dimensions of matrices being concatenated are not consistent.

2 vues (au cours des 30 derniers jours)
Please I have been struggling with this problem in my work since weeks. Please I will more than honored for your kind support. The occurs as below:
Error using horzcat
Dimensions of matrices being concatenated are not consistent.
Error in tvf_emd (line 50)
y = [fliplr(y(2:2+num_padding-1)) y fliplr(y(end-num_padding:end-1))]; % padding to deal with boundary effect (symmetric)
Please the attached is the code and data used.
  3 commentaires
Yussif M. Awelisah
Yussif M. Awelisah le 22 Sep 2019
y = [fliplr(y(2:2+num_padding-1)) y fliplr(y(end-num_padding:end-1))]; % padding to deal with boundary effect (symmetric)
% y=extendsignal(y,num_padding); % padding to deal with boundary effect (match slope)
The first question uses the second definition of y and the second question uses the first definition of y(default in the code).
Please I grateful for your concern. Hope you can help solve this problem.

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 22 Sep 2019
temp_x is 500 x 231. num_padding is 250 in that code.
In the expression
y = [fliplr(y(2:2+num_padding-1)) y fliplr(y(end-num_padding:end-1))]; % padding to deal with boundary effect (symmetric)
then y(2:2+num+num_padding-1) is y(2:251) . Using linear indexing of a 500 x 231 matrix, this is the same as y(2:251,1) except for the shape, a part of the first column, except that MATLAB happens to extract it as a row 1 x 250. fliplr() of that 1 x 250 is also 1 x 250.
y(end-num_padding:end-1) is linear indexing, so end has to be treated relative to linear indexing. y(end-num_padding:end-1) is then y(numel(y)-num_padding:numel(y)-1) which is y(500*231-250:500*231-1) which is y(115500-250:500*231-1) which is y(115520:115499) . This is the same as y(250:499, 231) except that MATLAB happens to extract it as a row 1 x 250. fliplr() of that 1 x 250 is also 1 x 250.
Thus the left and right hand side of the [] are both 1 x 250.
The middle, the y, is, as mentioned, 500 x 231. So you are trying to do
horzcat( 1 x 250 matrix, 500 x 231 matrix, 1 x 250 matrix)
However, the number of rows does not match -- 500 rows is not the same thing as one row.
I am unable to offer a correction to your code: I already offered you a suggestion in a previous question (that is, loop over the rows using the row index), but you appear to feel that is not correct for your situation and I have not been able to understand your explanation of why it did not work for you.
  4 commentaires
Yussif M. Awelisah
Yussif M. Awelisah le 23 Sep 2019
after using this, this occurs,
num_padding = round(size(temp_x,1)*0.5);% padding number
y = temp_x;
flag_stopiter=0;
for iter=1:100
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
Index exceeds matrix dimensions.
Error in tvf_emd (line 48)
y = [fliplr(y(2:2+num_padding-1)) y fliplr(y(end-num_padding:end-1))]; % padding to deal with boundary effect (symmetric)
Yussif M. Awelisah
Yussif M. Awelisah le 23 Sep 2019
At this point I have decided to give you the working code and data and the unworking code and data.
tvf_emd(1) is the original code and works perfectly with the data 'one sample'. running both data on tvf_emd(1), may help you understand my error better.

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by