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!