フィルターのクリア

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 Center および File ExchangeShifting and Sorting Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by