Converting symbols in columns to different numeric values
1 次查看(过去 30 天)
显示 更早的评论
Hello,
I need some help converting symbols in a matrix to integers. The thing is, I need eveery symbol to be a different value based on what column it is in. This is what I have so far:
%permutations
syms BUF TB TEN GB
picks1 = [BUF TB TEN GB];
orders1 = perms(picks1);
This outputs a matrix with all of the possible permutations of those four symbols.
I'd like to convert them to integers, but with the symbol meaning something different when it's in each column. i.e. for column 1 GB = 45, TB = 127, TEN = 128, KC = 131, for column 2 GB = 29, TB = 60, TEN = 64, KC = 71, etc.
Is there any way to do this easily using matlab?
Thank you in advance!
0 个评论
回答(1 个)
Walter Roberson
2022-1-20
syms GB KC TB TEN
picks1 = [GB TB TEN KC];
orders1 = perms(picks1);
GBv = [45; 29; 18; 7];
TBv = [127; 60; 34; 11];
TENv = [128; 64; 37; 13];
KCv = [131; 71; 38; 14];
temp = arrayfun(@(K) subs(orders1(:,K), picks1, [GBv(K), TBv(K), TENv(K), KCv(K)]), 1:size(orders1,2), 'uniform', 0);
output = [temp{:}]
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Number Theory 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!