Creating empty matrix with data in 1 cell

I want to generate an empty MATRIX containing all zeros apart from 1 or 2 cells which i want to assign a value to. Currently im using M = zeros(1,100); which generates my empty matrix but im unsure how to then assign a value to one of those cells.

回答 (1 件)

VBBV
VBBV 2022 年 2 月 14 日
編集済み: VBBV 2022 年 2 月 14 日

2 投票

M = zeros(1,100);
M(1,2:3) = 5% say 5
assign value of 5 to elements 2 and 3 in array

3 件のコメント

Ross Thompson
Ross Thompson 2022 年 2 月 14 日
Thanks a lot!
Ross Thompson
Ross Thompson 2022 年 2 月 15 日
How would this work if the elements wernt next bto each other in the MATRIX?
VBBV
VBBV 2022 年 2 月 15 日
M = zeros(1,100);
M(1,[2:3 10 20 30]) = 5% say 5
Set value of 5 to elements 2,3 10, 20, and 30. By brackets []

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

質問済み:

2022 年 2 月 14 日

コメント済み:

2022 年 2 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by