Indexing in a variable string in Matlab -


i have variable input names assign titles of graphs. e.g 'uktreasury_returns', 'china_logreturns', 'us_ret' ....

i want extract until underscore in each example. function arguments, have tried:

header = inputname(1); subject = header(1:'_'-1); finaltitle = [subject, ' - first 3 pcs']; 

the '-1' there because not want underscore included in output.

this didn't work, , rror message: 'index exceeds matrix dimensions'.

how can dynamically reference underscores? tips how solution might extended other indexing problems might face in future?

you can't index string constituent characters in matlab. when do:

header(1 : '_' - 1); 

matlab automatically converts char '_' integer index, kind of happens in c. since value of integer exceeds length of string, error mentioned.

to achieve trying do, can do:

strs = strsplit(header, '_'); subject = strs{1}; 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -