0

I need to convert a string of boolean indices into an array which would look like this:

convert('11001') = [1 2 5]
convert('0000') = []
convert('001') = [3]

I don't control the function which produces the string.

Any ideas to do this in an elegant way? I already did it whith a loop but it looks wrong somehow.

2 Answers 2

5
function y = convert(s)
y = find(s == '1');
Sign up to request clarification or add additional context in comments.

Comments

2

Here's a variation that converts each character to a number.

function y = convert(s)
y = find(str2num(s')')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.