tags:

views:

50

answers:

1

Given a string that represents the name of a person, how do I get the first two characters of this string as a new variable?

Is there a function in MATLAB that can do this, or do I need to program it in a MATLAB code file?

Jack --> Ja
Cleve --> Cl
+5  A: 

Strings are treated as arrays in matlab so you can use normal array notation.

personName = 'something';
firstTwoLetters = personName(1:2);
actually what Im trying to do is that i have a list of 2 names that are not on the worksapce im reading them from xls read and i want to get the first 2 letter ,ive tried to make the mfile but it gets an error function acro_profs= acro(profs)for i=1:length(profs) aux = profs{i} acro_profs(i,:)=aux(1:2)% here it says exceeded matrixend
mona
@mona: you probably have to add some error checking. It's hard to say though without a longer code snippet that clarifies what the variables "acro" and "profs" are.
qdjm
This is two different problems: Reading from Excel and String manipulation. They should be posted as separate questions.
MatlabDoug

related questions