matlab - Error with ^2, says matrix should be square -
i wanted plot following
y=linspace(0,d,100) temp=y^2; plot(y,temp);
i getting error y^2
, says matrix should square.
is there way plot.
you not getting error because of plot. getting because of
temp=y^2
instead, should using
temp=y.^2
^
means matrix power. .^
elementwise power. can find more matlab operators here.
let's have 3x3 matrix, magic(3).
a=magic(3) = 8 1 6 3 5 7 4 9 2
here square of matrix (which a*a, dan suggested):
a^2 ans = 91 67 67 67 91 67 67 67 91
here matrix contains squares of a's elements:
a.^2 ans = 64 1 36 9 25 49 16 81 4
Comments
Post a Comment