Format text string in matlab -


i'm trying extract parameter name string have:

vi('$excitation', '0a', '0a', '0a') 

i want "$excitation" out of it.

currently i'm using:

for = 1:length(parameters);     par{a,1} = sscanf ((parameters{a,1}),'vi(''%s, %*s, %*s, %*s,%*s')';     titles{1,a} = par{a,1}; end 

which gets me:

"$excitation'," 

i've tried changing :

'vi(''%s'',, %*s, %*s, %*s,%*s' 

and no change in result.

any suggestions? helpful explain why have doesn't work, don't make same mistake again!

edit:

i have similar problem "gi('magflux(current1): matrix1', 19, 131, 'wb')" i'd "magflux_wb" output

what work this:

op=textscan((parameters{a,1}),'%s','whitespace','','delimiter',' ''(),','multipledelimsasone',true); par{a,1} = op{2}; titles{1,a} = par{a,1}; 

as why original code didn't work, it's because sscanf reads %s until whitespace:

your string is:

vi('$excitation', '0a', '0a', '0a') 

putting vi( @ start of formatstring means gets ignored, '%s' searching through this:

'$excitation', '0a', '0a', '0a') 

it reads until hits whitespace: '$excitation', , matches first %s. comma inserted formatstring ignored until %s first dealt with, why didn't expected.

what remains then

'0a', '0a', '0a') 

which doesn't match rest of formatstring: , %*s, %*s, %*s,%*s') output isn't expected.

what did use textscan allows specify delimiters or whitespace want use split strings. stopped splitting strings spaces telling use no whitespace, , instead told use space, ', left , right brackets, , comma delimiters split sentence up, , if there 2 or more delimiters in row, count them single break (otherwise empty cell elements).


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -