Performing calculations on a vector

22 vues (au cours des 30 derniers jours)
ReturnToCastle
ReturnToCastle le 4 Mai 2020
I have a vector of (50,1) I need to apply a formula and perform calculations on each element in the vector how do I achieve this?
  2 commentaires
James Tursa
James Tursa le 4 Mai 2020
Depends on the formula and whether the functions involved are vectorized or not. You may have to write a loop. What is your formula?
ReturnToCastle
ReturnToCastle le 4 Mai 2020
It is 20log10(4πd/λ), where d represents the elements in the vector

Connectez-vous pour commenter.

Réponse acceptée

James Tursa
James Tursa le 4 Mai 2020
The log10( ) function is vectorized, so just this
result = 20 * log10(4*pi*d./lambda);
  1 commentaire
ReturnToCastle
ReturnToCastle le 4 Mai 2020
This helped a lot, thank you

Connectez-vous pour commenter.

Plus de réponses (1)

David Hill
David Hill le 4 Mai 2020
Using elementwise functions and operators.
v.^2;
v.*m;%v and m same size
v./m;%v and m same size
v.^m;%va and m same size
...

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by