필터 지우기
필터 지우기

How to make certain elements of a matrix equal to one?

조회 수: 3 (최근 30일)
James
James 2013년 10월 2일
댓글: Walter Roberson 2022년 9월 13일
For example, if I had:
x = zeros(1,100)
and I wanted to make the 3rd, 5th, 67th, and 93rd element equal to one, how could I do this?

채택된 답변

Walter Roberson
Walter Roberson 2013년 10월 2일
x([3, 5, 67, 93]) = 1;
  댓글 수: 2
Moe Joe
Moe Joe 2022년 9월 12일
But the problem in this solution the newly generated vector will be with 93 elements, so how to keep the new-x as 100 elements after the solution?
Walter Roberson
Walter Roberson 2022년 9월 13일
No, with that code, the size of x will not change unless it had fewer than 93 elements. But the user said that x = zeros(1,100) so we know that it already exists with 100 elements.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by