Performing calculations on a vector

조회 수: 15 (최근 30일)
ReturnToCastle
ReturnToCastle 2020년 5월 4일
댓글: ReturnToCastle 2020년 5월 4일
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
James Tursa
James Tursa 2020년 5월 4일
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 2020년 5월 4일
It is 20log10(4πd/λ), where d represents the elements in the vector

댓글을 달려면 로그인하십시오.

채택된 답변

James Tursa
James Tursa 2020년 5월 4일
The log10( ) function is vectorized, so just this
result = 20 * log10(4*pi*d./lambda);

추가 답변 (1개)

David Hill
David Hill 2020년 5월 4일
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
...

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by