# How do I add a column vector or matrix to a 6X6 original matrix?

8 views (last 30 days)
M.Bilal on 25 Jan 2020
Commented: M.Bilal on 4 Feb 2020
I have a 6x6 matrix, say C_m, in which some entries are zero and all other entries are cloumn vector c11, c12 & c44 eg c11 = [a11,a12,a13...], c12 = [b11,b12,b13...], c13 = [d11,d12,d13...], c44 =[e11,e12,13...]. All column vectors are of the order of 142x1 matrix.
How do I define the column vectors in a 6x6 matrix (C_m), so that matlab recognizes it?
C_m = [c11 c12 c12 0 0 0
c12 c11 c12 0 0 0
c12 c12 c11 0 0 0
0 0 0 2*c44 0 0
0 0 0 0 2*c44 0
0 0 0 0 0 2*c44]
When i run the program, following problem occur? how do i solve this?
Error using horzcat
Dimensions of matrices being concatenated are not
consistent.
Error in bilal2 (line 287)
287 C_m = [c11 c12 c12 0 0 0

M.Bilal on 27 Jan 2020
Hello, Stephen Cobeldic Kindly suggest me on following, as i am new to Matlab.
how i use a cell array in this problem. If you can learn me through an example, it will realy help me.
"If C_m is not required to be a numeric matrix then you could try a cell array:"
Guillaume on 27 Jan 2020
Before blindly trying things without understand what the implications are, please explain why you want to store several somethings that have size 142x1 into something that is size 6x6? Shouldn't the container be big enough to store the containee?
What are you planning to do afterward with C_m ? Yes, you could make C_m a cell array, but you won't be able to perform mathematical operations on the cell array itself, only on individual cells.
M.Bilal on 27 Jan 2020
Well, C_m is a stiffness matrix, in which c11,c12,c44 etc are stiffnesses.
c11, c12,c44 are column matrix , not a single value. I am planning to develop C_m matrix which contains c11,c12,c44.

Philippe Lebel on 27 Jan 2020
Edited: Philippe Lebel on 27 Jan 2020
here is an example:
clear all
zeros_col = zeros(142,1);
c11 = (1:142)';
fantastic_matrix = [c11 zeros_col zeros_col zeros_col zeros_col zeros_col;
zeros_col zeros_col zeros_col zeros_col zeros_col zeros_col;
zeros_col zeros_col zeros_col zeros_col zeros_col zeros_col;
zeros_col zeros_col zeros_col zeros_col zeros_col zeros_col;
zeros_col zeros_col zeros_col zeros_col zeros_col zeros_col;
zeros_col zeros_col zeros_col zeros_col zeros_col zeros_col]
That is if you want to have a matrix in order to compute some things with matrix multiplications.
If you want to just store things:
clear all
c11 = (1:142)';
fantastic_cell_array = {c11 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 0 0 0;
0 0 0 0 0 0}

M.Bilal on 3 Feb 2020
"explain why you're trying to store over 142 elements in something that can only store 36 elements. "
Well, S_eff can be solved by using single value in elements of all matrices.( means without 6x6 cell array).
But I DON'T NEED IT.
I am not using single vlaues at this time. I have to used whole wellog file at this time which consist of 1 cloumn and 142 rows, means a column vector. And this wellog file say c11 should be store in C_m matrix as element, similarly c12, c13, c44. My problem is that how can i solve S_eff by using S_d,S_m which consist of elements of column vectors like c11, c12, c13, c44.
"What are you planning to do afterward with C_m ? Yes, you could make C_m a cell array, but you won't be able to perform mathematical operations on the cell array itself, only on individual cells."
I got a clue from last line of yours which means i can perform mathematical operations on individual cells. This sentence is saying that i can use only those elements of array which consist of c11,c12,13,c44 for further caluculation like for the solution of S_eff.
Guillaume on 3 Feb 2020
Again, forget about matlab for now. In mathematics you don't store vectors as elements of a matrix. This bit makes no sense.
M.Bilal on 4 Feb 2020
Right.so nice of you. Thanks for time.

Steven Lord on 27 Jan 2020
C_m = [c11 c12 c12 0 0 0
c12 c11 c12 0 0 0
c12 c12 c11 0 0 0
0 0 0 2*c44 0 0
0 0 0 0 2*c44 0
0 0 0 0 0 2*c44]
If all of the c* variables are 142-by-1 vectors, you need to concatenate them with zero vectors that are also 142-by-1. Consider a smaller example:
V = [1; 2; 3];
D1 = [V, 0] % Fails
D2 = [V, zeros(size(V))] % Works
If you want to concatenate together 0's and vectors, you may want to make a variable that contains a zero vector of the appropriate size to make the sizes match.
V = [1; 2; 3];
Z = zeros(size(V));
A = [V Z Z; Z V Z; Z Z V]

#### 1 Comment

M.Bilal on 27 Jan 2020
Steven Lord, thankyou v.much for impressive answer. I am working on it.