is there an equivalent vlookup formula excel in matlab of a string?
1 回表示 (過去 30 日間)
古いコメントを表示
I have the following matrix:
Name_1 Name_2 ..... Name_n
23.5 25.8 29.6
24.5 85.5 ........ 59.2
A matrix (nxn), where in the first row ther'is the name of stocks, and in the other row the historical price. Then, I have another matrix of pair of stocks, for example:
Name_1 Name_2
Name_3 Name_5
and so on.... I want a code that give me for all pair the respective stock prince. For example for the first pair: Name_1 Name_2 I want to extrapolate the following matrix:
Name_1 Name_2
23.5 25.8
24.5 85.2
and so on. Thxs
0 件のコメント
回答 (2 件)
Image Analyst
2016 年 3 月 23 日
I'd use tables.
ca = {'Name_1' 'Name_2' 'Name_n';
23.5 25.8 29.6;
24.5 85.5 59.2}
% Convert cell array to table
numericalDataOnly = ca(2:end,:);
t = cell2table(numericalDataOnly);
% Make columns have the names we want.
t.Properties.VariableNames = ca(1,:)
% Make the other cell array
ca = {'Name_1' 'Name_2';
'Name_3' 'Name_5'}
% Extract columns for the first row
% which is the columns for Name_1 and Name_2 only.
row = 1; % Whatever you want, can even be a loop index
col1 = t{:, ca{row, 1}}
col2 = t{:, ca{row, 2}}
% Construct final array. It will be doubles, not a table.
output = [col1, col2]
Walter Roberson
2016 年 3 月 24 日
looking_up = {'Name_1', 'Name_2'};
[tf, colidx] = ismember(looking_up, YourCell(1,:));
Extract = YourCell(:, colidx(tf));
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Genetic Algorithm についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!