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

 채택된 답변

James Tursa
James Tursa 2016년 11월 8일
편집: James Tursa 2016년 11월 8일

0 개 추천

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).

추가 답변 (1개)

Marisol Riddell
Marisol Riddell 2016년 11월 8일

0 개 추천

THANK YOU!!!!! Oh my God, Thank you.... I have spent an hour trying to figure this out.. Did I say thank you yet? THANK YOUUUUU!!!!!!!!

카테고리

도움말 센터File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

질문:

2016년 11월 8일

답변:

2016년 11월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by