MATLAB Answers

Adding a single number to an entire matrix

조회 수: 7(최근 30일)
David Krouse
David Krouse 2021년 5월 13일
답변: Star Strider 2021년 5월 13일
How do you add a single number to each element within a matrix?
i.e.
a = 5
b = (1,2,3;4,5,6;7,8,9)
c = a + b

답변(1개)

Star Strider
Star Strider 2021년 5월 13일
Exactly as you wrote it!
a = 5
a = 5
b = [1,2,3;4,5,6;7,8,9]
b = 3×3
1 2 3 4 5 6 7 8 9
c = a + b
c = 3×3
6 7 8 9 10 11 12 13 14
Use square brackets [] to code vectors and matrices.

Community Treasure Hunt

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

Start Hunting!

Translated by