Azzera filtri
Azzera filtri

separating strings one by one

1 visualizzazione (ultimi 30 giorni)
Valeria Chacon
Valeria Chacon il 26 Ott 2016
Commentato: Star Strider il 26 Ott 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?

Risposta accettata

Star Strider
Star Strider il 26 Ott 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 Commenti
Valeria Chacon
Valeria Chacon il 26 Ott 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 il 26 Ott 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.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by