Hi all, I want to assign variables to my single column table data of strings in matlab

2 ビュー (過去 30 日間)
Bernard Opoku
Bernard Opoku 2017 年 7 月 27 日
回答済み: Saurabh Gupta 2017 年 7 月 31 日
say I have this data in a table type: b= 'come' 'go' 'see' 'west' 'done'
and I want assign letters from A-Z to each member. so I'll have something like 'come' = A. but since the data is more than 26 rows, I'd preferably have 'come'=A1, 'go'=B1 and the last string = Zn. Any inputs would be appreciated!
  2 件のコメント
Jan
Jan 2017 年 7 月 27 日
編集済み: Jan 2017 年 7 月 27 日
The question is not clear. What does "assign letters" mean? "'come'=A1" is no valid Matlab syntax, such that we have to guess, what you want to achieve.
I hope you do not want to create the variable called "come" dynamically, because this topic is discussed daily in this forum and the answer is always the same: DON'T DO THIS. It is a shot in your knee and there is always a better solution to solve the actual problem. See Tutorial: Don't EVAL.
Bernard Opoku
Bernard Opoku 2017 年 7 月 27 日
hi Jan, sorry for the confusion, assign here implies I can just write A1 in the next line if I need come. I could just use A to Z but since the data is more than 26, I will have to attach a number to it so it becomes infinite (A1 to Z1 and start again at A2 for the 27th index)
Hope this is clearer. Thanks

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

回答 (1 件)

Saurabh Gupta
Saurabh Gupta 2017 年 7 月 31 日
As I understand, you have a column vector of unique strings and you want to determine an index in the form of "Axx to Zxx" for each of these strings based on their indices in the vector. If my understanding is correct, then I think all you need is some modulo arithmetic and integer division .
For example, lets say 'come' is at index 'i' in the vector. Then the following command will give you an index of the required form.
>> newIndex = [char(64 + mod(i,26)), num2str(idivide(i,uint32(26)))]
Note that it is only a suggestive example to demonstrate the idea. You may need to play around with it. Hope this helps!

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by