How to convert all elements of a cell array to one string matrix.

Imagine this Example:
A = {'Steve';'wonder';'Marcus';'Jacob'};
and i want to convert to
B =['1-Steve 2-wonder 3-marcus 4-Jacob'];
I'm doing that inside of an loop!
What is the best way to solve that? Thanks

 採用された回答

Sean de Wolski
Sean de Wolski 2013 年 10 月 7 日

0 投票

A = {'Steve';'wonder';'Marcus';'Jacob'};
B = strjoin(strcat(cellstr(num2str((1:numel(A)).')),'-',A).',' ')
13a or newer for strjoin

1 件のコメント

Alan
Alan 2013 年 10 月 7 日
Thank you very much...exactly what I wanted!

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

その他の回答 (1 件)

Matt J
Matt J 2013 年 10 月 7 日
編集済み: Matt J 2013 年 10 月 7 日

0 投票

A loop is fine for something like that.

2 件のコメント

Alan
Alan 2013 年 10 月 7 日
The problem is I have hundreds of cells and each one has a different length and I want to put numbers like showed above.
Matt J
Matt J 2013 年 10 月 7 日
Your problem is not a problem. Even if you have 5000 cells, it will still be pretty fast.

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

カテゴリ

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

質問済み:

2013 年 10 月 7 日

コメント済み:

2013 年 10 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by