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

3 次查看(过去 30 天)
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