Selecting a specific part in a string array
Afficher commentaires plus anciens
Hello everone,
I want to wrtie a function that will separate first and last names at the input data. Input data is 30x1 cell array. It contains name and surname information. I try "split" function but some people has 2 or more names, so matlab gives size error. How can i fix it? My function as follows:
function seperation
strg = a1(:,1);
strg_cell=table2cell(strg);
i=1;
while i<31
x3(i,:)=split(strg_cell(i,1),' ');
i=i+1;
end
end
Réponse acceptée
Plus de réponses (1)
Stephen23
le 31 Déc 2021
tmp = split(strg_cell(i,1));
x3(i,:) = tmp([1,end]);
The MATLAB approach would be to use a simple FOR loop, rather than painfully incrementing in a WHILE loop as if this was C++.
Catégories
En savoir plus sur Cell Arrays dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!