필터 지우기
필터 지우기

i want to code such that the loop is constraint for two different values?

조회 수: 2 (최근 30일)
kitty varghese
kitty varghese 2017년 8월 28일
편집: KL 2017년 8월 28일
I want to code this equation
s(i)=x(i)+(l1-sum(x(i))/N
here the loop must be i=1:108300
and the value for l1 and x(i) must be same for first 300
here I something I tried.
for i2=1:108300
for i3=1:300
s(i2)=W(i2)+(l1-sum(W(:,i3)))/N;
end
end
  댓글 수: 3
KL
KL 2017년 8월 28일
편집: KL 2017년 8월 28일
Your question is still not clear.
What do you mean by the value for l1 and x(i) must be same for first 300? Is l1 a constant or a vector (like x)? If so, does it change only every 300 rows?
and what do you mean by sum(x(i).. Do you wanna make a sum of every 300 rows and keep it constant?
kitty varghese
kitty varghese 2017년 8월 28일
l1 is a constant which is same for batches of 300. sum(x(i)) is the sum of rows which i need to keep it constant for batches of 300.
therefore for easy, i have already calculated sum(x(i)) and kept in array k.

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

채택된 답변

KL
KL 2017년 8월 28일
편집: KL 2017년 8월 28일
N = 108300;
x = rand(N,1);
sum_rows = 300;
l1 = x(1:sum_rows:N); %take every 300th value
l1_r = reshape(repmat(l1,1,sum_rows)',N,1); %repeat it
sum_x = sum(reshape(x,N/sum_rows,sum_rows),2); %create a sum of every 300 rows
sum_x_r = reshape(repmat(sum_x,1,sum_rows)',N,1); %repeat 361 times to create a vector of N length
s=x+(l1_r-sum_x_r)./N;

추가 답변 (1개)

Walter Roberson
Walter Roberson 2017년 8월 28일
N = 108300;
x = rand(1, N);
x(1:300) = l1(1:300);
i = 1 : N;
s(i) = x(i)+(l1-sum(x(i))/N;
  댓글 수: 1
kitty varghese
kitty varghese 2017년 8월 28일
@Walter Roberson I want this process for the batch of every 300. ie the first 300 will take one value and second batch of 300 will take one value and so on ...for 361 times.

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by