how do I square a column in a matrix?
13 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Marisol Riddell
le 8 Nov 2016
Réponse apportée : Marisol Riddell
le 8 Nov 2016
Hello,
I have a 7x3 matrix and the last column needs to have each entry squared. How do I square the one column while keeping it in the same Matrix?
Thanks, Marisol btw.... I am BRAND new to Matlab
0 commentaires
Réponse acceptée
James Tursa
le 8 Nov 2016
Modifié(e) : James Tursa
le 8 Nov 2016
X = your 7x3 matrix
X(:,3) = X(:,3).^2; % replace 3rd column with its square (element-wise)
Note the dot in front of the ^ operator. That dot indicates element-wise operation. There are also .* and ./ for element-wise multiplication and element-wise division operators. The ^ and * and / without the initial dot indicates matrix operations (instead of element-wise operations).
0 commentaires
Plus de réponses (1)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!