Effacer les filtres
Effacer les filtres

separating strings one by one

1 vue (au cours des 30 derniers jours)
Valeria Chacon
Valeria Chacon le 26 Oct 2016
Commenté : Star Strider le 26 Oct 2016
N=length(str);
count=1;
for k=1:N
x=str2double(str(k));
if isnan(x)==0
str(count)=x(k);
count=count+1;
disp(x);
end
end
This is currently the code I have right now but it keeps giving me an error because the "index exceeds matrix dimensions on the line: str(count)=x(k); What am I doing wrong?

Réponse acceptée

Star Strider
Star Strider le 26 Oct 2016
your ‘x’ variable is a scalar, by definition a (1x1) ‘array’. So ‘x(k)’ is only valid for x=1.
This will likely eliminate that error:
str(count)=x;
  2 commentaires
Valeria Chacon
Valeria Chacon le 26 Oct 2016
is there any way that I can call for the 4th and 8th number of this code??? like if my result after it is:1256893490 then how can I pull out the 4th and 8th number of it? Thank you!
Star Strider
Star Strider le 26 Oct 2016
My pleasure!
I don’t know what ‘str’ is.
I assume that you would address them as:
str(4)
str(8)
respectively.
You can assign them as separate variables, but it is best to simply refer to them as elements of the vector.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by