How to display a matrix whose elements are strings?

Hi,
Consider we have two row matrices x and y. Both matrices have the same dimension 1 by m. I need to write a new string matrix z as z=[(x(1),y(1)),(x(2),y(2)),...,(x(m),y(m))]
Appreciated any help!

 採用された回答

Guillaume
Guillaume 2018 年 7 月 10 日
編集済み: Guillaume 2018 年 7 月 10 日

0 投票

Not entirely clear on exactly what output you want.
If you have indeed two string vectors, e.g.:
x = ["one", "two", "three"];
y = ["four", "five", "six"];
then
z = compose("(%s, %s)", x', y')'
or something similar is probably what you're after.

7 件のコメント

Hossein
Hossein 2018 年 7 月 10 日
For a simple case X=[1 7 4]; Y=[3 8 9]; What I want as output is: Z=[(1,3),(7,8),(4,9)]
Akira Agata
Akira Agata 2018 年 7 月 11 日
Almost the same. Please try the following.
X = [1 7 4];
Y = [3 8 9];
Z = compose("(%d, %d)", X', Y')';
Hossein
Hossein 2018 年 7 月 11 日
Thanks for your answer. This code results in "(1,3)" "(7,8)" "(4,9)" But I need exactly an output like Z=[(1,3),(7,8),(4,9)]. Z is originally a matrix of high dimension (1 by m where m is greater than 2000). So I don't wanna be bothered modifying the output by adding commas and deleting "s.
Walter Roberson
Walter Roberson 2018 年 7 月 11 日
Do you mean that you need the output to be a single string object that starts with "Z = [", and then has all of those pairs in () with commas between them, ending in "]" ?
Hossein
Hossein 2018 年 7 月 11 日
編集済み: Hossein 2018 年 7 月 11 日
Yes, exactly. and please consider that I need a solution for Z with m pairs.
Walter Roberson
Walter Roberson 2018 年 7 月 11 日
編集済み: Walter Roberson 2018 年 7 月 11 日
output = "Z = [" + strjoin(Z, ',') + "]";
where Z is as suggested by Akira Agata
Hossein
Hossein 2018 年 7 月 11 日
Thanks Walter. This works.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCharacters and Strings についてさらに検索

タグ

質問済み:

2018 年 7 月 10 日

編集済み:

2018 年 7 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by