Locating variables across multiple tables
Mostra commenti meno recenti
Hi, I'm trying to track a certain variable through several data sets and look at some corresponding numbers as time goes on.I have 91 excel sheets with 10,000 lines, but I'll make a silly simplified example..... I need to know how many fleas are on a dog every year, but the order of the dogs changes, and sometimes new dogs are added... year 1:
- Spike 10
- Mr.Dog 12
- Chow 11
Year 2:
- Spike 11
- Chow 13
- Mr.Dog 15
Year 3:
- * Spike 18
- * Chow 17
- * Mr.Dog 16
- * Charlie 20
I need an outcome that looks sort of like this
- * Spike 10 11 18
- * Chow 11 13 17
- * Mr.Dog 16...etc
- * Charlie 20
I created a loop that picks a name as a variable and then scrolls through the column containing names until it finds a match, in which case it grabs the corresponding values from the same row. I'm having a tough time with errors defining what a variable is...can a text/number combo not be a variable? does it need to be in parentheses? I imagine there is an easier way to do this in general.
for i=1:9572;
if CO01(i,3)==302;
t302(i,1,1)=CO01(i,3);
t302(i,2,1)=CO01(i,4);
t302(i,3,1)=CO01(i,5);
t302(i,4,1)=CO01(i,6);
t302(i,5,1)=CO01(i,9);
t302(i,6,1)=i;
%y=y+1;
end
end
for i=1:9500;
nt302(i,1,1)=t302(i,2,1);
nt302(i,1,2)=t302(i,3,1);
nt302(i,1,3)=t302(i,4,1);
nt302(i,1,4)=t302(i,5,1);
end
for i=1:9500;
row=t302(i,6,1);
name1=nCO01(row,1);
for j=1:9500;
if nCO03(j,1)==name1(1,1);
nt302(j,2,1)= CO03(j,4);
nt302(j,2,2)= CO03(j,5);
nt302(j,2,3)= CO03(j,6);
nt302(j,2,4)= CO03(j,9);
end
end
end
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Matrix Indexing in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!