Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
Alan
Alan le 7 Oct 2013
Commenté : Alan le 7 Oct 2013
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

Réponse acceptée

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

Plus de réponses (1)

Matt J
Matt J le 7 Oct 2013
Modifié(e) : Matt J le 7 Oct 2013
A loop is fine for something like that.
  2 commentaires
Alan
Alan le 7 Oct 2013
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 le 7 Oct 2013
Your problem is not a problem. Even if you have 5000 cells, it will still be pretty fast.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by