필터 지우기
필터 지우기

code using if but didn't work?? any help

조회 수: 1 (최근 30일)
arkedia
arkedia 2014년 8월 6일
댓글: Star Strider 2014년 8월 6일
i want to make a subcod in a simulation as follows 1- choose the lowest numberin
a=[9 5 6 1 -5 0 2] 2- replace this value with 1 and other numbers with zeros to be
newa=[0 0 0 0 1 0 0]
my sub code is
a=[9 5 6 1 -5 0 2]
newa=size(a)
j=min(a)
for i=1:7
if a(1,i)==j; then newa(1,i)==1;
else
newa(1,i)==0;
end
end
But it didnt work ANY HEELP

채택된 답변

Kelly Kearney
Kelly Kearney 2014년 8월 6일
You have a typo in your then statement... should be
newa(1,i) = 1;
not
newa(1,i) == 1;
But you can replace the entire code with
a = [9 5 6 1 -5 0 2];
newa = a == min(a);
  댓글 수: 1
Star Strider
Star Strider 2014년 8월 6일
True, but we have:
newa=[0 0 0 0 1 0 0]
then:
newa=size(a)

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by