Error using horzcat Dimensions of matrices being concatenated are not consistent.
5 views (last 30 days)
Show older comments
Yussif M. Awelisah
on 21 Sep 2019
Commented: Yussif M. Awelisah
on 23 Sep 2019
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.
Accepted Answer
Walter Roberson
on 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 Comments
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!