Read through header number and add correponding columns from different arrays
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Image Analyst
2014-6-10
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!