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 CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by