Matlab String (1000) conversion into (1 0 0 0)

Hy my question is that I have a string like x = 1000 I want to convert it into matrix like 1 0 0 0. Can you please guide me how to convert it.

 Accepted Answer

Is x a character vector, or a string vector? If char, do this:
x = '1000';
y = x - '0';
If a string, you could simply convert to character. Thus,
x = "1000";
y = char(x) - '0';
Other ways I am sure.

More Answers (0)

Categories

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!