Converting symbols in columns to different numeric values

1 回表示 (過去 30 日間)
Dan Ring
Dan Ring 2022 年 1 月 20 日
コメント済み: Dan Ring 2022 年 1 月 21 日
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!

回答 (1 件)

Walter Roberson
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{:}]
output = 
  1 件のコメント
Dan Ring
Dan Ring 2022 年 1 月 21 日
Fantastic! Thank you very much.

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

カテゴリ

Help Center および File ExchangeNumber Theory についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by