Function with sum of vector elements
古いコメントを表示
Hi, so I am trying to plot the furrier transform of a set of data. A is a row vector with:
A = [0.0001:0.0001:0.08]
And B is the row vector with the Y values for the sound wave, with the same dimension so that a function g can be defined as mapping from every nth element of A to every nth element of B
The function that I came up to give me the furrier transform was:
function [ f_intensity ] = FT_g( f )
f_intensity = sum(B.*exp(-2*pi*1i*f.*A));
end
Both A and B are in my workspace but it keeps saying that the variable B is undefined.
>> FT_g(1)
Undefined function or variable 'B'.
Error in FT_g (line 3)
f_intensity = sum(B.*exp(-2*pi*1i*f.*A));
Anyone has any idea how I could solve this?
1 件のコメント
Matt J
2019 年 2 月 7 日
I am trying to plot the furrier transform
Not to be confused with the fuzzier transform... ;)
回答 (1 件)
Star Strider
2019 年 2 月 7 日
You need to pass ‘A’ and ‘B’ as arguments to your funciton:
function [ f_intensity ] = FT_g( f, A, B )
Then call it the same way.
Note that ‘A’, ‘B’, and ‘f’ all have to have the same dimensions.
2 件のコメント
Mathias Sven Strassburger Maluf
2019 年 2 月 7 日
Star Strider
2019 年 2 月 7 日
If ‘f’ is one frequency, I would do something like this:
A = [0.0001:0.0001:0.08];
B = sin((0 : 50 : 150)'*A); % Create ‘B’
f = 10;
f_intensity = @(f,A,B) sum(B.*exp(-2*pi*1i*f.*A));
figure
plot(A, abs(f_intensity(f,A,B)))
grid
See if that does what you want.
カテゴリ
ヘルプ センター および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!