Filter löschen
Filter löschen

What is the meaning of symbol “.”in this code

1 Ansicht (letzte 30 Tage)
Shuoze Xu
Shuoze Xu am 16 Mär. 2022
Bearbeitet: Jan am 16 Mär. 2022
I was watching a tutorial today on graphics, and one line of code went like this.
x = linspace(0,3); y = x.^2.*sin(x); plot(x,y);
What does the sign "."? Does it have any specific meaning?
Thank you all.

Akzeptierte Antwort

Jan
Jan am 16 Mär. 2022
Bearbeitet: Jan am 16 Mär. 2022
While ^ is the power operation, which acts on the complete array, .^ is the elementwise power. For a scalar, this is no difference:
a = 17;
a ^ 2 % 289, same as a * a
a .^ 2 % 289, same as a * a
a = [2, 3];
a ^ 2 % ERROR, same as [2, 3] * [2, 3] - this is not defined
a .^ 2 % [4, 9], same as [2^2, 3^2]
% And equivalent to: a .* a
The power operator ^ is defined for square matrices only.
The same for .* : * multiples the arrays, while .* operates on the array elements.

Weitere Antworten (1)

Arif Hoq
Arif Hoq am 16 Mär. 2022

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by