1

I currently have a large single row array of chars... I also have two arrays, the first array has all the start indexes of data I would like to retrieve from the char array, the second array has all the end indexes for the data. How can I retrieve all these wanted values from my char array without using a loop?

So far I have tried doing

     chararray(1,start(:):end(:))

but this will only retrieve the first value I would like!

Cheers!

4
  • Don't you need a loop - for iter = 1:numel(start), chararray(1,start(iter):end(iter)), where iter would be the loop iterator? Commented Sep 25, 2014 at 10:51
  • @Divakar Hi I was hoping there would be a simpler way as this loop would be extremely large! Commented Sep 25, 2014 at 10:53
  • Are the intervals same for all entries of start and end? Intervals as in start(1):end(1), start(2):end(2) and so on. Commented Sep 25, 2014 at 10:54
  • @Divakar They all are yes! :) Commented Sep 25, 2014 at 10:57

1 Answer 1

2

Try this -

chararray(bsxfun(@plus,start1(:)-start1(1),start1(1):end1(1)))

This would create a 2D char array where each row be the output from each iteration of your loop code.

Also, please note that I am using start1 and end1 to represent your start and end arrays respectively, so as not to create a clash with the reserved terminate scope end used by MATLAB.

Sign up to request clarification or add additional context in comments.

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.