Effacer les filtres
Effacer les filtres

array of strings into 2 number array

5 vues (au cours des 30 derniers jours)
fima v
fima v le 17 Fév 2017
Commenté : Walter Roberson le 17 Fév 2017
Hello, i have an array of 3 strings,each string is consists of two numbers spaced by tab. i would like to create a 2X3 2D array.i thought of going with for loop using strsplit and str2num. is there an easier way,without for loop?
Thanks
  1 commentaire
Walter Roberson
Walter Roberson le 17 Fév 2017
Is this a cell array of strings, or a char array?

Connectez-vous pour commenter.

Réponse acceptée

KSSV
KSSV le 17 Fév 2017
str = {'apple' 'boy'} ; % you may take numbers
repmat(str,2,3)
  1 commentaire
Walter Roberson
Walter Roberson le 17 Fév 2017
? This does not appear to be related to the needs of the Question ?

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 17 Fév 2017
TAB = sprintf('\n');
output = str2double( cellfun(@(S) strsplit(S, TAB), YourCell, 'Uniform', 0) );
or
temp = regexp(YourCell, '\t', 'split');
output = str2double( vertcat(temp{:}) );

Catégories

En savoir plus sur Data Type Conversion 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