Filter löschen
Filter löschen

Creating empty matrix with data in 1 cell

3 Ansichten (letzte 30 Tage)
Ross Thompson
Ross Thompson am 14 Feb. 2022
Kommentiert: VBBV am 15 Feb. 2022
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.

Antworten (1)

VBBV
VBBV am 14 Feb. 2022
Bearbeitet: VBBV am 14 Feb. 2022
M = zeros(1,100);
M(1,2:3) = 5% say 5
assign value of 5 to elements 2 and 3 in array
  3 Kommentare
Ross Thompson
Ross Thompson am 15 Feb. 2022
How would this work if the elements wernt next bto each other in the MATRIX?
VBBV
VBBV am 15 Feb. 2022
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 []

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by