Replace elements in array

3 ビュー (過去 30 日間)
Oscar
Oscar 2014 年 10 月 24 日
コメント済み: Oscar 2014 年 10 月 24 日
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 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2014 年 10 月 24 日
This is not clear, illustrate with a small example, show the expected result

サインインしてコメントする。

回答 (1 件)

Guillaume
Guillaume 2014 年 10 月 24 日
Use the second output of ismember for that:
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
  1 件のコメント
Oscar
Oscar 2014 年 10 月 24 日
thnx, i'll try that!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by