Performing calculations on a vector

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 Commenti

Depends on the formula and whether the functions involved are vectorized or not. You may have to write a loop. What is your formula?
It is 20log10(4πd/λ), where d represents the elements in the vector

Accedi per commentare.

 Risposta accettata

The log10( ) function is vectorized, so just this
result = 20 * log10(4*pi*d./lambda);

Più risposte (1)

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

Categorie

Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange

Prodotti

Release

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by