Filter löschen
Filter löschen

separating strings one by one

1 Ansicht (letzte 30 Tage)
Valeria Chacon
Valeria Chacon am 26 Okt. 2016
Kommentiert: Star Strider am 26 Okt. 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?

Akzeptierte Antwort

Star Strider
Star Strider am 26 Okt. 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 Kommentare
Valeria Chacon
Valeria Chacon am 26 Okt. 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 am 26 Okt. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by