Read through header number and add correponding columns from different arrays
1 view (last 30 days)
Show older comments
Hi,
I have following arrays.
H=[438 440 441 449 455 457 459 460 462 467 468 469 473 476 478 479 481 483 485 486 487];
All_St1=[440 449 457 462 467;
rand(100,1) rand(100,1) rand(100,1) rand(100,1) rand(100,1)];
All_St2=[438 441 462 468 473 479;
rand(100,1) rand(100,1) rand(100,1) rand(100,1) rand(100,1) rand(100,1)];
All_St3=[455 478 479 481 483 485 486;
rand(100,1) rand(100,1) rand(100,1) rand(100,1) rand(100,1) rand(100,1) rand(100,1)];
I need to check the header numbers from H, first row of All_St1, All_St2 and All_St3. Then if the header numbers are matching/similar from All_St1, 2 and 3 then sum/add the corresponding columns from row 2:end.
For example, under header number 462, All_St1 4th column and All_St2 3rd columns shoud be summed/added.
Output matrix (Out) should have 101 rows the header numbers H. If there is no header number of H in All_St1,2,and 3, the corresponding column should be empty/zero.
Can somebody help me to implement this in MATLAB?
Thanks in advance.
0 Comments
Answers (1)
Image Analyst
on 10 Jun 2014
Did you try a nested for loop? It's very simple/basic. A brute force method but should be very fast especially for arrays this small. Come on, give it a try. I know you can do it if you just make an attempt because a for loop is about the very first thing you learn in programming. Here, I'll get you started...
for hk = 1 : length(H)
hValue = H(hk)
for hs = 1 : size(All_St1, 2)
value1 = All_St1(1, hs);
value2 = All_St2(1, hs);
value3 = All_St3(1, hs);
if ........
end
end
See if you can finish it.
See Also
Categories
Find more on Matrices and Arrays 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!