Error using vertcat: dimension of arrays being concenated are not consistent

1 view (last 30 days)
Hello,
I am using xlsread (x=xlsread(filename,sheet,xlrange))
to obtain values for x from my excel file, x is a 27x1 double.
(x=
1.01
1.05
0.004
0.65
etc...)
Then I have matrix A (nx27). I try to call some of the values for A from x, for example(i present just a few rows for the idea):
A= [1 -1 0 1 1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; % just some random row
0 0 0 1 -1 0 x(20) 1 0 (x(21)-x(23)) 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
A is a jacobian matrix I use , so some elements for A are calculation operations from partial differentials.
When i use this, it gives me the error using vertcat: dimensions of arrays being concatenated are not consistent
The error points to the line where the term 'A=' is. Does it have something to do with it? Anyways, i didnt find an answer after searching for 5 hours from here and trying few things.
Any idea why this happens? is it something with xlsread? I am completely lost with this. Should i use something different for obtaining values for x from excel?
BR,
Jouni
  2 Comments
Jouni Salovaara
Jouni Salovaara on 14 May 2019
Edited: Jouni Salovaara on 14 May 2019
Right, sorry about that. Here is the code, left out irrevelant stuff. I have already calculated the partial differentials on paper and just wrote the results as the matrix A to the script. The idea for me is just to bring values from x to the matrix A. The matrix A does not change in this exercise, only the values of x.
path='C:\Users\user\location\Matlab';
filename='importfile.xlsx';
fullpath= [path, '\', filename];
sheet2='values';
xlrange3= 'A2:A28';
x=xlsread(filename,sheet2,xlrange3);
A=[1 -1 0 1 1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 1 1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 1 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 1 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 1 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 1 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
x(14) -x(15) (u(4) - x(16)) 0 0 0 0 0 0 0 0 0 0 x(1) -x(2) -x(3) -u(2) 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 (-x(21)+x(23)) 0 0 0 0 0 0 0 0 0 0 0 0 0 -x(7) 0 x(7) 1 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 1 1 1;
x(13) -x(15) 0 x(17) x(19) -x(20) (x(21)-x(23)) 0 0 0 0 0 x(1) 0 x(2) 0 x(4) 0 x(5) -x(6) x(7) 0 -x(7) 0 0 0 0;
0 0 0 0 0 0 (x(21)-x(22)) 0 0 0 0 0 0 0 0 0 0 0 0 0 x(7) -x(7) 0 0 -1 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 u(2) -u(2) 0 0 0 0 0 0 1 0 0;
0 0 0 0 0 0 (x(22)-u(4)) 0 0 0 0 0 0 0 0 0 0 0 0 0 x(7) 0 0 0 -1 0 0;
0 0 (x(15)-u(3)) 0 0 0 0 0 0 0 0 0 0 0 0 0 x(3) 0 0 0 0 0 0 0 0 0 1];
and here is the error:
Error using vertcat
Dimensions of arrays being concatenated are not consistent.
Error in test (line 23)
A=[1 -1 0 1 1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;

Sign in to comment.

Accepted Answer

Guillaume
Guillaume on 14 May 2019
The error is simple. At least one of the rows of your A does not have the same number of elements as the others.
Certainly,
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 1 1 1;
x(13) -x(15) 0 x(17) x(19) -x(20) (x(21)-x(23)) 0 0 0 0 0 x(1) 0 x(2) 0 x(4) 0 x(5) -x(6)
x(7) 0 -x(7) 0 0 0 0;
is clearly wrong since that last row has only 7 elements. Note that newlines in a matrix construction are equivalent to semicolons.

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!