## columns of a matrix

### Josep (view profile)

on 21 Aug 2014
Latest activity Commented on by Andrew Reibold

on 22 Sep 2014

### Andrew Reibold (view profile)

I would like to know how to achieve one by one the columns of a matrix. Let me put here what I have done:

` %COMBINATION OF ONE VARIABLE.`

%we first read all the variables

Nby=53 ; % Le nombre des variables mesurées

y = xlsread('C:\Users\p105312\Desktop\dig+echg+washer+evap.xlsx' ,'E14:E66' ); % Les valeurs des variables mesurées

Nbz=5; % Le nombre des variables non mesurées

z =xlsread('C:\Users\p105312\Desktop\dig+echg+washer+evap.xlsx' ,'E75:E79' ); % Une estimation de la variable non mesurée extraite de la simulation

Nbc=15 ; % Le nombre de contraintes de systéme

Cp = xlsread('C:\Users\p105312\Desktop\dig+echg+washer+evap.xlsx' ,'D89:D94' ); % Les capacités calorifiques

y = xlsread('C:\Users\p105312\Desktop\dig+echg+washer+evap.xlsx' ,'E14:E66' ); % Les valeurs des variables mesurées

``` Ay = [       1,       1,       1,       1,       -1,       -1,       -1,       -1,       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, 0, 0, 0,    0,   0,    0,    0,    0,       0,       0,        0,        0,       0,       0,       0,        0,        0
; Cp(2)*y(12), Cp(4)*y(13), Cp(5)*y(14), Cp(3)*y(15), -Cp(5)*y(16), -Cp(3)*y(17), -Cp(5)*y(18), -Cp(5)*y(19),       0,  Cp(5)*y(21),  Cp(5)*y(22), Cp(2)*y(1), Cp(4)*y(2), Cp(5)*y(3), Cp(3)*y(4), -Cp(5)*y(5), -Cp(3)*y(6), -Cp(5)*y(7), -Cp(5)*y(8),      0,  Cp(5)*y(10),  Cp(5)*y(11), 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,        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, 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,        1,        1,       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, 0, 0, 0,    0,   0,    0,    0,    0,       0,       0,        0,        0,       0,       0,       0,        0,        0`
`       ;      0,       0,       0,       0,        0,        0,  Cp(5)*y(18),  Cp(5)*y(19), Cp(2)*y(20), -Cp(5)*y(21), -Cp(5)*y(22),      0,      0,      0,      0,       0,       0,  Cp(5)*y(7),  Cp(5)*y(8), Cp(2)*y(9), -Cp(5)*y(10), -Cp(5)*y(11), 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,        0,        1,        0,        0,       0,        0,        0,      0,      0,      0,      0,       0,       0,       0,       0,      0,        0,        0, 1, 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,        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,   1, 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,       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,    1, 1, 1, 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,        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,    1, 1, 1, 1, 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,      0,      0,      0,       0,       0,       0,       0,      0,        0,        0, 0, 0, 0, y(41), 0, -z(4), -y(42), 0, 0, 0,  0,    0, 0, 0, 0, 0, 0,    0, y(26), -y(29),    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, 0,   0, 0,   0,  y(42), 0, 0, 0,  0, -y(43), 0, 0, 0, 0, 0,    0,   0,  y(29), -y(34),    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,   0, 0,   0,    0, 0, 0, 0,  0,  y(43), 0, 0, 0, 0, 0, -y(44),   0,    0,  y(34), -y(40),       0,       0,        0,        0,       0,       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, 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`
`       ;       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, 0, 0, 0, 0,    0,   0,    0,    0,    0,       1,       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,        0,        0, 0, 0, 0,   0, 0,   0,    0, 0, 0, 0,  0,    0, 0, 0, 0, 0, 0,    0,   0,    0,    0,    0, Cp(2)*y(49), Cp(5)*y(50), -Cp(1)*y(52), -Cp(5)*y(53), Cp(2)*y(45), Cp(5)*y(46), -Cp(2)*z(5), -Cp(1)*y(47), -Cp(5)*y(48)];`

%----------------------------------

for j=1:Nby,

`    for i=1:Nbc,`
`        A(i,j)=Ay(i,j);`
`    end`
```    A
end```

#### 1 Comment

Matz Johansson Bergström

### Matz Johansson Bergström (view profile)

on 21 Aug 2014

It would be nice if you could put the examples as a attached file and make the example smaller.

## Products

No products are associated with this question.

### Andrew Reibold (view profile)

on 21 Aug 2014
Edited by Andrew Reibold

### Andrew Reibold (view profile)

on 21 Aug 2014

To call the entire contents of a column of a matrix, use matrix name and the colon operator (:)

Para encontrar la columna de una matriz, utilice el nombre de la matriz y el operador dos puntos (:)

```A = [1 2 3;...
4 5 6;...
7 8 9];
```
```A(:,1) = [1; 4; 7]
A(:,2) = [2; 5; 8]
```

and so on.

The colon tells Matlab to take the data from every row giving you the entire colomn.. The second number says which column to take from. You can put things like 'i' from your loop in there too.

Josep

### Josep (view profile)

on 22 Aug 2014

Thank you Andrew!

Josep

### Josep (view profile)

on 3 Sep 2014

I have to obtain a test statistics from an equation (T), for a thermodynamic process. Fk matrix is made of variables (columns) and constraints (rows). In my code the only changing matrix would be Fk, so I have to obtain the test for all the possible combinations of 2 variables of Fk(15x2) without repeating any.

the combination of the variables should be like this (where this variables are the columns of Fk):

1,2

1,3

1,4

1,5

1,6

2,3

2,4

2,5

2,6

3,4

......

5,6

I attach here the Excel file of the measured values of the variables from 1 to 6 and the matlab code I have done for the combination of one variable.

Do you know how should be the code for all the combinations like this?

Andrew Reibold

### Andrew Reibold (view profile)

on 22 Sep 2014

I honestly didn't see your follow up question unless about 3 weeks after you posted it. People often don't see new questions in the comments, including myself. Would recommend reposting this as a new, specific question, and include the detail you just did again.

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test