matlab - finding a comma in string -


[23567,0,0,0,0,0] , other value [452221,0,0,0,0,0] , value should contineously displaying 100 values , want display sensor value in first sample 23567 , in second sample 452221 , these values have display . have written code
value = str2double(str(2:7));see here attempt i want find comma in output , display value before first comma

as proposed in comment excaza, matlab has dedicated functions, such sscanf such purposes.

sscanf(str,'[%d') 

which matches ignores first [, , returns next (i.e. first) number double variable, , not string.

still, idea of using regular expressions match numbers. instead of matching zeros , commas, , replacing them '' proposed sardar_usama, suggest directly matching numbers using regexp.

you can return numbers in str (still string!) with

nums = regexp(str,'\d*','match') 

and convert first number double variable with

str2double(nums{1}) 

to match first number in str, can use regexp

nums = regexp(str,'[(\d*),','tokens') 

which finds [, takes arbitrary number of decimals (0-9), , stops when finds ,. enclosing \d* in brackets, parts in brackets returned, i.e. numbers without [ , ,.

final note: if continue working strings, could/should consider regexp solution. if convert double anyways, using sscanf faster , easier.


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - IE9 error '$'is not defined -