Process two matrices with condition
1 view (last 30 days)
Show older comments
Hello,
I have two matrices: A(343x9) and B(369x4). They are attached with this thread. Column 8 in matrix A represents length and columns 2 and 3 in matrix B represent coordinates. What I want to achieve is that I want to copy column 8 of matrix A to column 4 of matrix B, starting from the second row with condition - it checks whether sqrt((B(i+1,2)-B(i,2))^2 + (B(i+1,3)-B(i,3))^2) is EQUAL TO A(i,8). If TRUE write the value of A(i,8) to B(i+1,4). If FALSE write zero. The output is expected to be:
1 355.303500000000 176.975500000000 0
2 353.808900000000 176.170700000000 1.69750764357630
3 352.199200000000 175.480800000000 1.75131267910672
4 350.704500000000 174.905900000000 1.60144875035077
5 344.150900000000 173.526200000000 6.69725653159563
6 338.057100000000 173.066300000000 6.11112971961812
7 332.883200000000 172.951300000000 5.17517789162846
8 330.238700000000 172.491400000000 2.68419229191948
9 325.179800000000 170.651800000000 5.38299148893995
10 321.615500000000 169.387100000000 3.78202334471907
11 317.016500000000 167.777400000000 4.87256965984068
12 310.117900000000 165.247900000000 7.34772428783225
13 309.313100000000 164.903000000000 0.875590686336942
14 307.933300000000 163.983200000000 1.65827623754310
15 306.553600000000 163.178400000000 1.59727115105729
16 305.058900000000 161.108800000000 2.55291446194347
17 304.484100000000 160.303900000000 0.989069790257485
18 304.024200000000 158.694300000000 1.67401319289903
19 303.564200000000 157.084600000000 1.67413681937887
20 303.679200000000 154.555100000000 2.53211280356937
21 303.794200000000 151.565800000000 2.99151123848801
22 305.288900000000 146.046900000000 5.71772553556046
23 306.553600000000 142.367700000000 3.89049851947021
24 301.609600000000 140.298100000000 5.35969963337501
25 299.080200000000 139.033300000000 2.82799989391797
26 297.010600000000 138.228500000000 2.22057361958570
27 518.224900000000 225.150500000000 0
28 507.187100000000 230.324500000000 12.1902955189774
29 505.002600000000 236.763100000000 6.79908892499577
Your help is greatly appreciated. Thank you.
0 Comments
Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!