Read through header number and add correponding columns from different arrays

1 Ansicht (letzte 30 Tage)
Damith
Damith am 10 Jun. 2014
Bearbeitet: Damith am 10 Jun. 2014
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.

Antworten (1)

Image Analyst
Image Analyst am 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.
  1 Kommentar
Damith
Damith am 10 Jun. 2014
Bearbeitet: Damith am 10 Jun. 2014
Hey Thanks. But did you see size(All_St1,2 and 3) are diffrent? How can I check for header numbers for All_St's. If your example you check for first 5. But All_St2 and 3 have more columns.
How can I find the similar row numbers from value1, value2 and value3? Any thought on that.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by