Replace elements in array
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have a 1 048 000 by 7 cell array, A, with stock data (one row for every stock and time), all values are numbers apart from the identifying ISIN-numbers which are strings (looking like 'AB00063033' etc.). I have created another 700 by 2 cell array, B, with two columns, one with ISIN-numbers and one with a corresponding identifying number. I want to replace the ISIN-numbers in the larger array with the corresponding identifying numbers from the smaller array.
Essentially doing changem(A,B(:,2),B(:,1)), but for a cell array instead of a matrix.
I have done a small for-loop that solves this, but it takes an eternity with over a million elements to check. Are there any easy commands that solves my problem?
Thanks!
1 Kommentar
Azzi Abdelmalek
am 24 Okt. 2014
This is not clear, illustrate with a small example, show the expected result
Antworten (1)
Guillaume
am 24 Okt. 2014
a = {1 2 3 4 5 6 'ABxxxx';
8 9 10 11 12 13 'CDxxxx';
15 16 17 18 19 20 'ABxxxx';
22 23 24 25 26 27 'EFxxxx'};
b = {'ABxxxx' 12345;
'CDxxxx' 78910;
'EFxxxx' 98765}
[found, idx] = ismember(a(:, 7), b(:, 1)); %match column 7 of a with column 1 of b
if ~all(found)
error('b is missing some ISIN')
end
a(:, 7) = b(idx, 2); %replace column 7 of a with column 2 of b
Siehe auch
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!