I want to apply for loop. Below is my code. I have applied the for loop which is wrong. Here Length(t) is sample numbers. Here I want to create 'for' loop for a sample number 5 in particular. so how to change the for loop. Moreover, 'phi_sync' shoud be sample number of 5 and 'phi_acc' shoud be summation from 0 to 5 sample numbers.
fs = 200;
ts = 1/fs;
t = 0:ts:1-ts;
fc = 50;
S = cos(2*pi*fc*t); % equation 7.1 noisless
sigma = 1.8;
phi_sync = sigma * randn(1,length(t)); % random variable with gaussian distributed
phi_acc = sigma * randn(1,length(t)); % random variable with gaussian distributed
% h = 0;
for i=1:length(S)
h = phi_sync + phi_acc(i);
end

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2015년 7월 28일
편집: Azzi Abdelmalek 2015년 7월 28일

0 개 추천

k=0
h=zeros(size(1:5:numel(S)))
for ii=1:5:numel(S)
k=k+1
h(k)= phi_sync(ii) + phi_acc(ii);
end

댓글 수: 7

Kutru biladi
Kutru biladi 2015년 7월 28일
Gey Aziz. Thanks for edit and reply. I want Phi_sync as only 5th element and phi_acc as summation from 1 to 5.
Kutru biladi
Kutru biladi 2015년 7월 28일
yes, its working. Thanks :)
Azzi Abdelmalek
Azzi Abdelmalek 2015년 7월 28일
편집: Azzi Abdelmalek 2015년 7월 28일
Biladi, my name is Azzi not Aziz.
You don't need a for loop to do it
n=numel(t)
a=sigma * randn(1,n);
b=sigma * randn(1,n)
phi_sync = a(5)
phi_acc = sum(b(1:5))
Kutru biladi
Kutru biladi 2015년 7월 28일
hey Aziz, this is not exactly i am looking for, now i realised. :D. as i told u before i want Phi_sync as only 5th element and phi_acc as summation from 1 to 5.
Kutru biladi
Kutru biladi 2015년 7월 28일
Sorry Azzi, for mispelling your name :D. ya now i got my answer.
Kutru biladi
Kutru biladi 2015년 7월 28일
Hey Azzi, one more questoion. now i want to add this h = phi_sync(5) + phi_acc(sum(1:5). how to get this h using for loop from o to n.
Kutru biladi
Kutru biladi 2015년 7월 28일
I mean now h(5) = phi_sync(5) + phi_acc(sum(1:5). i want h(1) to h(n) and after that i need to add this h in a signal. S1 = cos(2*pi*fc*t + h) so i will get phase noise

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2015년 7월 28일

댓글:

2015년 7월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by