Borrar filtros
Borrar filtros

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

3 visualizaciones (últimos 30 días)
James
James el 2 de Oct. de 2013
Comentada: Walter Roberson el 13 de Sept. de 2022
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?

Respuesta aceptada

Walter Roberson
Walter Roberson el 2 de Oct. de 2013
x([3, 5, 67, 93]) = 1;
  2 comentarios
Moe Joe
Moe Joe el 12 de Sept. de 2022
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 el 13 de Sept. de 2022
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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by