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!