Elementwise addition operation in matrix or array
显示 更早的评论
BD is 33*3 data.
BD=[ 1 0 0
2 100 60
3 90 40
4 120 80
5 60 30
6 60 20
7 200 100
8 200 100
9 60 20
10 60 20
11 45 30
12 60 35
13 60 35
14 120 80
15 60 10
16 60 20
17 60 20
18 90 40
19 90 40
20 90 40
21 90 40
22 90 40
23 90 50
24 420 200
25 420 200
26 60 25
27 60 25
28 60 20
29 120 70
30 200 600
31 150 70
32 210 100
33 60 40];
BD(:,2)
I want to add data element wise in 2nd column and replace the data in BD.
Suppose addtion of 100 in BD (2,2) should update BD(2,2) to 200. Remaining column data should be as it is.
P(2)=100
BD(:,2) = BD (:,2)+_________
回答(1 个)
David Hill
2022-2-10
If you are just adding a scalar to column 2 of BD
BD(:,2)=BD(:,2) + Scalar;
2 个评论
David Hill
2022-2-10
If P is the same length as B, then
BD(:,2)=BD(:,2)+P;
If P is a different length
m=min(size(B,1),length(P));
BD(1:m,2)=BD(1:m,2)+P(1:m);
Sanket Raval
2022-2-11
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!