Error using horzcat in code trying to get rid of discontinuities

2 views (last 30 days)
Hi everyone!
When i run this code
(it reads an image rotates it then gets 100 profiles of the same length from the image and then tries to eliminate the discontinuities in the profiles)
img101 = imread('c1=100.800.1.0.1.png');
img_rot= imrotate(img101,32.06);
for i=1:100
x_0 = [1 800];
y_0 = [1 501.06];
y = improfile(img101,x_0,y_0)
yOrig = y;
limit = 0.2;
dy = [0, diff(y)];
jump = strfind(abs(dy) > limit, [false, true, false]);
for ijump = 1:numel(jump)
k = jump(ijump);
y(k+1:end) = y(k+1:end) - dy(k+1);
axes('NextPlot', 'add')
plot(x, yOrig, '-r', x, y, 'bo')
y2 = lowpass(y, 30, 200);
plot(x, y2, 'c+')
i get the next error:
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
Error in lowpass_discontinuities_simple (line 34)
dy = [0, diff(y)];
Does anyone know why?
I have attached the image im reading

Accepted Answer

Voss on 22 Dec 2021
This error happens because 0 is a scalar (i.e., it has size 1 in all dimensions) and diff(y) is of size not equal to 1 in some dimension(s) other than dimension 2, which is the dimension of concatenation with horizontal concatenation (i.e., using [] for concatenation), so that 0 and diff(y) cannot be horizontally concatenated. Try this instead:
dy = [zeros(size(y,1)-1,1,size(y,3)), diff(y)];

Sign in to comment.

More Answers (0)


Find more on Image Processing and Computer Vision 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!