Why do I get the error “Dimensions of arrays being concatenated are not consistent.”?

1 629 views (last 30 days)
Can anybody help me why my code show me this error when i run it? i have attached my code.
  19 Comments
Sarvesh
Sarvesh on 6 Jan 2024
Edited: Sarvesh on 6 Jan 2024
You could do without the "What else where you expecting?" line. Also it could be better to not misuse words. Its "were" not "where".

Sign in to comment.

Accepted Answer

Roger Wohlwend
Roger Wohlwend on 4 Jun 2014
Edited: MathWorks Support Team on 27 Nov 2018
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]
  3 Comments
Misrak Seifu
Misrak Seifu on 4 Jun 2014
Now it's giving this error below...
Warning: Control Character '\U' is not valid. See 'doc sprintf' for control characters valid in the format string. > In sample_gui>save_Callback at 225 In gui_mainfcn at 95 In sample_gui at 42 In @(hObject,eventdata)sample_gui('save_Callback',hObject,eventdata,guidata(hObject))

Sign in to comment.

More Answers (2)

Ivan Dwi Putra
Ivan Dwi Putra on 27 Nov 2019
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);

kevin harianto
kevin harianto on 8 Apr 2022
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")

Categories

Find more on Graphics Object Properties 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!