简体   繁体   English

Matlab代码崩溃并给出错误:所连接矩阵的维数不一致

[英]Matlab code crashes and gives error: Dimension of matrices being concatenated are not consistent

Kindly have a look at this code and help me out. 请看一下这段代码,帮帮我。 I am doing something wrong with the Matlab line command. 我用Matlab line命令做错了。 The code give warnings and then crashes. 该代码给出警告,然后崩溃。 The error is in the 2nd last line. 错误在第二行。

while ~isDone(videoSource)
frame = readFrame(videoSource);
mask = detectObjects(frame,Fgdetector);
[areas, centroids, bboxes]= step(blobAnalyser,mask);

% tracing boundires around the detected obbjects

% BW = im2bw(I, graythresh(I));
[B,L] = bwboundaries(mask,'noholes');
imshow(label2rgb(L, @jet, [.5 .5 .5]))
hold on

 for k = 1:length(B)
 boundary = B{k};
 plot(boundary(:,2), boundary(:,1), 'w', 'LineWidth', 2)
 %for star skeleton
 x = boundary(:,2);
 y = boundary(:,1);
 indexes = convhull(x, y);

 hold on;

%  plot(x(indexes), y(indexes), 'm-', 'LineWidth', 2);
 line([x(indexes(k)), centroids], [y(indexes(k)),centroids ], 'Color', 'r', 'LineWidth', 2);

end

What I suspect is happening is that centroids is a N x 2 array, or a 2 x N array and you are trying to concatenate a matrix with a single value to create another matrix. 我怀疑发生的是centroids是一个N x 2数组或2 x N数组,并且您试图将一个具有单个值的矩阵连接起来以创建另一个矩阵。 The sizes are inconsistent and so that's why you're getting that error. 大小不一致,所以这就是为什么您会收到该错误。 I don't know what shape centroids is (ie if it's N x 2 or 2 x N ) because detectObjects is something you wrote, or a function that exists in a later version of MATLAB that I don't have access to, so one of these should work. 我不知道形centroids是什么形状(即,它是N x 2还是2 x N ),因为detectObjects是您编写的东西,或者是我无法访问的更高版本的MATLAB中存在的函数,因此这些应该工作。 When you use line you need to provide the x locations and ending y locations for each segment of the line that you want. 使用line ,需要为所需线条的每个线段提供x位置和y结尾位置。

Assuming that the first row/column is the x coordinates and the second row/column is the y coordinates, do this: 假设第一行/列是x坐标,第二行/列是y坐标,请执行以下操作:

centroids - N x 2

line(centroids(:,1), centroids(:,2), 'Color', 'r', 'LineWidth', 2);

centroids - 2 x N

line(centroids(1,:), centroids(2,:), 'Color', 'r', 'LineWidth', 2);

As a minor note, the x and y variables in the line call look like they are coordinates for the convex hull of your shapes. 作为次要说明, line调用中的xy变量看起来像是形状凸包的坐标。 You are trying to combine these with the centroids... which doesn't really make any sense. 您正在尝试将它们与质心结合起来……这实际上没有任何意义。 Stick with drawing one or the other. 坚持画一个或另一个。 If you want to draw both, then make two separate line calls: 如果要同时绘制两者,请进行两个单独的线路调用:

line(centroids(:,1), centroids(:,2), 'Color', 'r', 'LineWidth', 2);
% or
% line(centroids(1,:), centroids(2,:), 'Color', 'r', 'LineWidth', 2);
line(x(indexes), y(indexes), 'Color', 'r', 'LineWidth', 2);

Don't mix apples and oranges together. 不要将苹果和橙子混合在一起。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用CAT的matlab错误,所连接矩阵的维数不一致 - matlab error using CAT, Dimensions of matrices being concatenated are not consistent matlab连接的矩阵尺寸不一致 - matlab Dimensions of matrices being concatenated are not consistent 我如何处理“使用vertcat的错误连接矩阵的尺寸在Matlab中不一致”? - How do i handle “Error using vertcat Dimensions of matrices being concatenated are not consistent” in Matlab? 我的代码运行,有时会出现错误“使用horzcat时出错,所连接的矩阵维数不一致。” - My code runs then sometimes it has error “Error using horzcat Dimensions of matrices being concatenated are not consistent.” 使用垂直时发生错误:串联的矩阵尺寸不一致 - Error using vertical: Dimensions of matrices being concatenated are not consistent 如何解决:使用horzcat时发生错误所连接矩阵的维数不一致 - How to solve: Error using horzcat Dimensions of matrices being concatenated are not consistent bsxfun:所连接矩阵的维数不一致 - bsxfun: Dimensions of matrices being concatenated are not consistent 在MATLAB中调试错误“被连接的数组的维度不一致” - Debugging the error "Dimensions of arrays being concatenated are not consistent" in MATLAB 使用带有字符的数组时,要级联的矩阵的维数不一致 - Dimensions of matrices being concatenated are not consistent using array with characters 在1x6802 double和6802x1 double数据矩阵中,级联矩阵的尺寸不一致 - Dimensions of matrices being concatenated are not consistent in 1x6802 double and 6802x1 double data matrix
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM