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

Can anybody help me why my code show me this error when i run it? i have attached my code.

19 Commenti

The error means you are trying to concatenate a row array with a column array. You'll need to tell us at what line the code fails and attach the fig file for people to try your code.
I cop and pasted the error below..and i have attached the fig file
Error using vertcat Dimensions of matrices being concatenated are not consistent.
Error in sample_gui>save_Callback (line 216) attributes=[get(handles.male,'Value'),get(handles.female,'Value'),get(handles.multiplefaces,'Value'),get(handles.partialfaces,'Value'),
Error in gui_mainfcn (line 95) feval(varargin{:});
Error in sample_gui (line 42) gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)sample_gui('save_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
First, you'll need the ... at the end of each line that is interrupted, e.g.,
attributes=[get(handles.male,'Value'),get(handles.female,'Value'),get(handles.multiplefaces,'Value'),get(handles.partialfaces,'Value'),...
Then, are the choices mutually exclusive? i.e. if you select male, can you select female too?
On line 216, try replacing the commas with semicolons between elements.
Yes the choices are mutually exclusive..I am about to replace the commas.
I'd recommend replacing the check boxes with radio buttons then. In your GUI I could select more than one option per panel, which is clearly inconsistent with what you are trying to do.
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))
what is currentimagefile(1:indx-1)?
That is the .mat file where i save after i make the selections
The reason for which i pick until indx-1 is that when you get the name it also shows the extension which in this case would be ".jpg". Thus we only get the name and then add ".mat"
can you show exactly the value of that variable?
Sir/Madam i also got this error,how to correct it?I cant get it from the above comment. X = [zeros(WLEN, 2); x; zeros(NFFT, 1000)'] size(zeros(WLEN,2)) ans = 1 2 >> size(x) ans = 2 1000 >> size(zeros(NFFT,1000)') ans = 1000 512 ------------------------ Error using vertcat Dimensions of matrices being concatenated are not consistent. Error in stft (line 45)
X = [zeros(WLEN, 2); x; zeros(NFFT, 1000)']
The error for the specifc code occurs because a specific line does not end with a "..."
A=[5 1 1 -1;1 8 -1 -6;1 2 -4 1; 1 2 -1 16]
B=[2 -72 256 -11]
%ELIMINACIÓN
[AB]=[A B];
X1=rref(AB)
@Daryl Eduardo Sanchez Huamani Of course that will give you an error. What else where you expecting? You are trying to add an array of size 1x4 to an array of size 4x4. That would work if you tried to add it as the next row, but you tried to add it as the next columns. To do that, you need to make sure the number of rows match between the two arrays.
and the award for most condescending responce goes to ....... @Rik
Condescension is in the eye of the beholder. I pointed out why the error occured as well as a path to a solution, so my comment at least has some value in that regard.
Do you have a suggestion for how I should refrase my comment? Or did you just want to start a flame war? In the former case, feel free to comment with your suggestion. In the latter case I will delete this comment.
You could do without the "What else where you expecting?" line. Also it could be better to not misuse words. Its "were" not "where".
the matlab community is horrible.
this message is brought to you by python gang.

Accedi per commentare.

 Risposta accettata

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 Commenti

Ok thank you, i am trying to fix it but i am not really good on this, it's my first time using matlab
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))

Accedi per commentare.

Più risposte (2)

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);
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")

Categorie

Community Treasure Hunt

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

Start Hunting!

Translated by