MATLAB Answers

Specific row and column addition for a NxM matrix

1 view (last 30 days)
WARRIOR24
WARRIOR24 on 21 Apr 2021
Edited: Scott MacKenzie on 27 Apr 2021
I am trying to add and subtract specfici rows and colums, the sum function is not working working for me; it is either suming up all of the values or adding all columns only.
1.1125 2.0641 2.3183 1.8751 1.2631 0.6625
3.4084 5.1874 5.2771 3.6026 2.1510 1.0079 1.) I am trying to sum up all the outside elements starting from
10.000 10.000 10.000 5.1074 2.7302 1.2181 3.4084 and ending at 2.8216
5.3388 6.2794 6.0136 4.0968 2.4445 1.1343 2.) As well as these 3 elements going in the inside starting from
2.9655 3.7652 3.6784 2.8216 1.8166 0.8745 10.000 and ending at 3.6784
1.6518 2.1375 2.1130 1.6946 1.1259 0.5472
0.8781 1.0199 0.9417 0.7178 0.4451 0.1884 4.) then subtract the outter from inner with the abs function
0.4931 0.6300 0.6188 0.5039 0.3377 0.1618
0.2869 0.3881 0.3997 0.3411 0.2401 0.1213
0.1692 0.2358 0.2506 0.2208 0.1603 0.0832
0.0971 0.1354 0.1462 0.1313 0.0971 0.0511
0.0472 0.0625 0.0674 0.0611 0.0456 0.0242

Answers (1)

Scott MacKenzie
Scott MacKenzie on 21 Apr 2021
Edited: Scott MacKenzie on 27 Apr 2021
% assume the data are in z
outLogical = z > 3.4084 & z < 2.8216;
inLogical = z < 10.000 & z > 3.6874;
sumOuter = sum(z(outLogical));
sumInner = sum(z(inLogical));
result = abs(sumInner - sumOuter);

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by