Clear Filters
Clear Filters

separating strings one by one

1 view (last 30 days)
Valeria Chacon
Valeria Chacon on 26 Oct 2016
Commented: Star Strider on 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?

Accepted Answer

Star Strider
Star Strider on 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 Comments
Valeria Chacon
Valeria Chacon on 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 on 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.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!