Error using horzcat in code trying to get rid of discontinuities

1 次查看(过去 30 天)
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
prof_img_rot(1:256,i)=img_rot(212+i,400:655)';
end
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);
end
figure
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

采纳的回答

Voss
Voss 2021-12-22
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)];
  4 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by