columns of a matrix
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Josep
le 21 Août 2014
Commenté : Andrew Reibold
le 22 Sep 2014
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,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 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 commentaire
Matz Johansson Bergström
le 21 Août 2014
It would be nice if you could put the examples as a attached file and make the example smaller.
Réponse acceptée
Andrew Reibold
le 21 Août 2014
Modifié(e) : Andrew Reibold
le 21 Août 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.
3 commentaires
Andrew Reibold
le 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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!