필터 지우기
필터 지우기

Changing values in vector

조회 수: 2 (최근 30일)
Mr.Chandler
Mr.Chandler 2020년 11월 16일
댓글: Mr.Chandler 2020년 11월 16일
Hello I have 1000 datas created by "randn" (A=randn(1,1000)). I want to change every value(n) which is not suitable for 1 < abs(A(n)) < 10. Also, new values should have been created by randn again. And it should provides the 1 < abs(A(n)) < 10 condition. So, I think have to create for loop for changing values until they provide the condition. How can I do that?

채택된 답변

Setsuna Yuuki.
Setsuna Yuuki. 2020년 11월 16일
편집: Setsuna Yuuki. 2020년 11월 16일
You can try this code
a = abs(randn(1,1000))
cont = 1;
while cont < length(a)+1
if(a(cont) < 1 || a(cont) > 10)
a(cont) = randn(1);
cont = 0;
end
cont = cont+1;
end
  댓글 수: 3
Setsuna Yuuki.
Setsuna Yuuki. 2020년 11월 16일
ohh i didn't see it, but it should work without abs()
Mr.Chandler
Mr.Chandler 2020년 11월 16일
Yes, I think it is okay. I arrange it a little bit. Thanks so much.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by