필터 지우기
필터 지우기

Turning array values into values on an x axis

조회 수: 2 (최근 30일)
Tom
Tom 2012년 5월 1일
Suppose I had a double array and the values were 2,3,6 and 9.
How would I create a double array where all of the values are 1, except the 2nd, 3rd, 6th and 9th, which are 2?
  댓글 수: 2
Daniel Shub
Daniel Shub 2012년 5월 1일
You link to double seems broken.
What have you tried so far?
Matt Fig
Matt Fig 2012년 11월 2일
Tom's question
Suppose I had a double array and the values were 2,3,6 and 9.
How would I create a double array where all of the values are 1, except the 2nd, 3rd, 6th and 9th, which are 2?

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

채택된 답변

Wayne King
Wayne King 2012년 5월 1일
x = ones(500,1);
indices = [2 3 6 9];
x(indices) = 2;
Or
x = ones(500,1);
x(indices) = x(indices)+1;
  댓글 수: 3
Daniel Shub
Daniel Shub 2012년 5월 1일
Ummm, it is 1x4 in Wayne's answer. It works if you make it 4x1.
Tom
Tom 2012년 5월 2일
Thanks - I got there in the end - I had to round my indices for some reason. Even though some of them had .0000 after it still wouldn't work until those had been removed.
Many thanks Wayne and Daniel.

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

추가 답변 (0개)

카테고리

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

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by