MATLAB: String array and Numeric values

arraycell arraysstring

Hi,,
I have a String array that contains Names, I want to allow the user to choose a Name to change either by writing the name as a string OR by writing it's index as a number..
So I wrote this code, but it seems faulty.. Can anyone help with this..
Thanks in advance:
clear all
clc
Nums=[1:5]
%NumsStr=num2str(Nums)
for i=1:5
s=input('s= ','s')
s=strtrim(s);
S{i}=(s);
clc
end
S
for i=1:5
tst=input('edit what ','s')
try
res=strmatch(tst,S,'exact')
if((length(res)~=0) && (length(res)<2))
S{res(1)}=input('TEXT_MODE, New String =','s')
else
%NumRes=strmatch(tst,num2str(Nums))
NumRes=find(Nums==tst)
if((length(NumRes)~=0) && (length(NumRes)<2))
S{NumRes(1)}=input('NUMBER_MODE, New String = ','s')
end
end
catch ME
end
end

Best Answer

In your original code, you should change the line after the else statement to:
NumRes=find(Nums==str2num(tst))