Error using horzcat in code trying to get rid of discontinuities
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponse acceptée
Voss
le 22 Déc 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)];
4 commentaires
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!