Use a for loop inside a vector

조회 수: 2 (최근 30일)
Una Ib
Una Ib 2017년 11월 16일
댓글: Una Ib 2017년 11월 17일
The first part was to make a rectangle vector and the second part is to make a curve vector that uses the data from the recktangle and adds a signal with the maximum amplitude noise. I got the first part down, so, I'm trying to get a vector with a for loop inside of it. What I have for now:
curve= [];
for i=1:numel(recktangle)
recktangle(i) = recktangle(i) + (rand() * noise);
end
curve= curve(:);
but it says that curve seems to be unused. How do I nest a for loop in an array?
  댓글 수: 4
Una Ib
Una Ib 2017년 11월 16일
First vector has a random number of zeros the second has a random number of ones. These two steps should be repeated N times and then linked together in a new rectangle vector.
Curve vector is a rectangle vector+ a random signal with max. amplitude noise.
KL
KL 2017년 11월 16일
...First vector has a random number of zeros the second has a random number of ones...
what are the sizes? Please be specific and give a complete explanation. It's always better to create a sample input and expected output.
as far as your explanation on curve vector goes, my answer does exactly that.

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

채택된 답변

KL
KL 2017년 11월 16일
I'm not sure what you want, but probably something like this (no need for loop, just one line like below),
curve = recktangle+(rand(size(recktangle))*noise);

추가 답변 (0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by