Why do I get the error “Dimensions of arrays being concatenated are not consistent.”?
1,629 次查看(过去 30 天)
显示 更早的评论
Can anybody help me why my code show me this error when i run it? i have attached my code.
19 个评论
采纳的回答
Roger Wohlwend
2014-6-4
编辑:MathWorks Support Team
2018-11-27
This error is encountered when you try to vertically concatenate arrays that do not have compatible sizes. For example, to vertically concatenate two matrices A and B, they must have the same number of columns:
A = ones(2,3)
B = ones(5,3)
C = [A; B]
C is a matrix with 7 rows and 3 columns.
However, if B has 4 columns instead of 3, you will get the error. For example,
B = ones(5,4)
C = [A; B]
For more information on concatenation in general, see https://www.mathworks.com/help/matlab/math/creating-and-concatenating-matrices.html.
3 个评论
更多回答(2 个)
Ivan Dwi Putra
2019-11-27
I have the same error too
this is my code
close all
% Initial Conditions
% x0 = [3; % 3 radians
% 0]; % 0 rad/s
%Parameter Massa
m1 = 650; % massa train set 1 dalam kg
m2 = 650; % massa train set 2 dalam kg
%Parameter Gaya
f1 = 1170; % dalam N
f2 = 1170; % dalam N
t = [0:100:1000];
% System Dynamics
% a = f1./m1 - (0.004 + (0.00032.*(1.5-(0.015.*sin(0.2.*t)-50))));
% b = f2./m2 - (0.0025 + (0.0004.*(1.6-(0.01.*sin(0.3.*t)-50))));
A = [0 1 0 0
0 f1./m1 - (0.004 + (0.00032.*(1.5-(0.015.*sin(0.2.*t)-50)))) 0 0
0 0 0 1
0 0 0 f2./m2 - (0.0025 + (0.0004.*(1.6-(0.01.*sin(0.3.*t)-50))))];
B = [0;
1/m1
0
1/m2];
C = [1 1 1 1];
D = 0;
% Control Law
Q = [1 0 0 0;
0 1 0 0
0 0 1 0
0 0 0 1];
R = [1 0 0 0;
0 1 0 0
0 0 1 0
0 0 0 1];
K = lqr(A,B,Q,R);
% Closed loop system
sys = ss((A - B*K), B, C, D);
0 个评论
kevin harianto
2022-4-8
I am wondering if there is a way to dynamically adjust this as my error is also error using horzcat, dimensions of the arrays are not consistent: at Location = [Location, ptCloud.Location];
outputFolder = fullfile(tempdir,"Pandaset");
preTrainedMATFile = fullfile(outputFolder,"trainedSqueezeSegV2PandasetNet.mat");
preTrainedZipFile = fullfile(outputFolder,"trainedSqueezeSegV2PandasetNet.zip");
if ~exist(preTrainedMATFile,"file")
if ~exist(preTrainedZipFile,"file")
disp("Downloading pretrained model (5 MB)...");
component = "lidar";
filename = "data/trainedSqueezeSegV2PandasetNet.zip";
preTrainedZipFile = matlab.internal.examples.downloadSupportFile(component,filename);
end
unzip(preTrainedZipFile,outputFolder);
end
% Load the pretrained network.
outputFolder = fullfile(tempdir,"Pandaset");
load(fullfile(outputFolder,"trainedSqueezeSegV2PandasetNet.mat"),"net");
% Read the point cloud.
%Next we shall change the outputfolder to face towards the data_2
outputFolderNew=fullfile("data_2");
ptCloud = pcread(fullfile(outputFolderNew,"0000000000.pcd"));
%Due to the ptCloud being a different data type
%With the above information in mind (trying to reach 64 in height)
% In order to match with the Expected file format we shall append additional matrices of 0
% in order to subsitute for the lack of clear resolution.
%These additional values should allow the raw pcd file matric to meet the
%resolutions demand
% Since we are only trying to influence the resolution
% (pandaSet Ideal resolution being 64x1856x3)
% and not the actual
% value's representation we will only be adding in the values.
Location = zeros(64, 1856, 3);
%next we shall add in the ptCloud.Location values
Location = [Location, ptCloud.Location];
%Now that we have added in the additional resolution we
% shall now create a new ptCloud variable for replacement.
tempPtCloud = ptCloud;
%next we shall change the Location properties.
tempPtCloud.Location = Location;
%Then we shall utilize the new ptCloud and treat it as the original
ptCloud = tempPtCloud;
% Convert the point cloud to 5-channel image.
im = helperPointCloudToImage(ptCloud);
% Predict the segmentation result.
predictedResult = semanticseg(im,net);
% Display sematic segmentation result on point cloud
% This should now be displaying our pointClouds that we want to add in and
% analyze for our use case.
helperDisplayLabelOverlaidPointCloud(im,predictedResult);
view([39.2 90.0 60])
title("Semantic Segmentation Result on Point Cloud")
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Object Properties 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!