Copy data for one table to another
24 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Juan Martinez
le 29 Juil 2018
Modifié(e) : Stephen23
le 30 Juil 2018
Hi all, i am working with tables and i have one problem. I have one table:

This table have unique sort index values (1,2,3...) and the values in second column that i want copy.
The other table that i want to paste the values with his index is:

The result would be:

How i can make this? I am trying to have some indexing such as:
if true
B.coefic = [B A(B,2)];
end
But wrong results.
Thank you very much!
0 commentaires
Réponse acceptée
Stephen23
le 30 Juil 2018
Modifié(e) : Stephen23
le 30 Juil 2018
[~,idx] = ismember(B.Fecha,A.Fecha);
B.coeff = A.values1(idx)
Or
B = A(idx,:)
Demonstrated using numeric arrays:
>> A = [1,2,3,4,5,6,7;15,12,18,11,19,10,14].'
A =
1 15
2 12
3 18
4 11
5 19
6 10
7 14
>> B = [1,1,1,2,2,3,3,3,4,5,5,6,7].'
B =
1
1
1
2
2
3
3
3
4
5
5
6
7
>> [~,idx] = ismember(B,A(:,1));
>> A(idx,:)
ans =
1 15
1 15
1 15
2 12
2 12
3 18
3 18
3 18
4 11
5 19
5 19
6 10
7 14
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Tables dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!