need to create a loop with on this problem
情報
この質問は閉じられています。 編集または回答するには再度開いてください。
古いコメントを表示
i will put the data and then explain my problem
f=1:0.2:20 (matrix 1x96)
i=lenght(f)
ti= a matrix 82x1
yi= a matrix 82x1
the equations that are given to me to solve the problem are :
eq.1
T=(1/(4*pi*f))*(atan(sum(sin(4*pi*f*ti)))/(sum(cos(4*pi*f*ti))))
eq.2
P(f)=(((sum(yi*sin(2*pi*f*(ti-T)))).^2/(sum(sin(2*pi*f*(ti-T)).^2))+ ((sum(yi*cos(2*pi*f*(ti-T))).^2)/(sum(cos(2*pi*f*(ti-T)).^2))))*0.5;
so i need to calculate eq.1 (gives me the value of T, so i can do eq.2. i want the P(f), calculates for every value of f.
so in the end i can plot (f,p(f)) and get my periodrogram.
i have to adapt the equation so i can have the values that i need, because if i do the loop with the eq. that are given me it will give me the error" matrix dimensions are not the same"
I tried but the values that the eq.2 is giving me are wrong.
0 件のコメント
回答 (1 件)
Geoff Hayes
2015 年 11 月 7 日
編集済み: Geoff Hayes
2015 年 11 月 7 日
João - are you looping over the values of f so that different values of T? If that is the case, then try the following
P = [];
k = 1;
for f=1:0.2:20
T=(1/(4*pi*f))*(atan(sum(sin(4*pi*f*ti)))/(sum(cos(4*pi*f*ti))));
P(f)=(((sum(yi*sin(2*pi*f*(ti-T)))).^2/(sum(sin(2*pi*f*(ti-T)).^2))+ ((sum(yi*cos(2*pi*f*(ti-T))).^2)/(sum(cos(2*pi*f*(ti-T)).^2))))*0.5;
k = k + 1;
end
The above may do what you expect, but there is a problem with your line of code for
P(f)=(((sum(yi*sin(2*pi*f*(ti-T)))).^2/(sum(sin(2*pi*f*(ti-T)).^2))+ ((sum(yi*cos(2*pi*f*(ti-T))).^2)/(sum(cos(2*pi*f*(ti-T)).^2))))*0.5;
There is a bracket mismatch, and (if that is resolved) there is an Inner matrix dimensions must agree. error with
(sum(yi*sin(2*pi*f*(ti-T))))
and
(sum(yi*cos(2*pi*f*(ti-T))).^2)
which you will need to resolve. You may also want to verify other parts of the equation too. For example, the above two lines are similar but the first may have more brackets than intended.
3 件のコメント
João Bernardo
2015 年 11 月 7 日
João Bernardo
2015 年 11 月 7 日
編集済み: Geoff Hayes
2015 年 11 月 7 日
Geoff Hayes
2015 年 11 月 7 日
While that is different than what I showed, the result is the same: in either example, we iterate over the different values of f. What is the problem with the above? Have you fixed the unbalanced parenthesis?
この質問は閉じられています。
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!