Is there a matrix which can be alphanumeric?

4 ビュー (過去 30 日間)
Jay Vaidya
Jay Vaidya 2020 年 11 月 11 日
回答済み: Cris LaPierre 2020 年 11 月 11 日
I am trying to make a matrix like
1n -1
1n 2
1n 1
1n 3
The first column is going to be concatenated string where the first alphabet is the counter of the for loop and the alphabet 'n'
For ex: for coun = 1:1:10
code will go here
end
should give output for coun = 3 as:
3n
3n
3n
3n
and then I need to put this along with a new matrix j which is
-1
2
1
3
The order of the final matrix is decided by the matrix j as it has the same number of rows as the number of rows of the matrix j.
So the final output is:
3n -1
3n 2
3n 1
3n 3

採用された回答

Cris LaPierre
Cris LaPierre 2020 年 11 月 11 日
A matrix cannot contain mixed data types. It's possible to create a string array that does what you want, but everything will have to be strings.
a = string(ones(4,1)*3)+"n";
b = [-1 2 1 3]';
j=[a string(b)]
j = 4×2 string array
"3n" "-1" "3n" "2" "3n" "1" "3n" "3"
If instead you want to mix data types, you could use a table.
j=table(a,b)
j = 4x2 table
a b ____ __ "3n" -1 "3n" 2 "3n" 1 "3n" 3

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by