MATLAB Answers


sprintf literal output as next pending command

Asked by Octavian on 25 Dec 2014
Latest activity Commented on by Jan
on 29 Dec 2014
Dear All,
I have a cell array DD with cells containing strings formed from letters, eg 'SFG' (some consecutive cells have identical contents, say 'SFG', but not all; essentially, DD is a list of name roots). I try to use the following code:
for i=1:2:(length(DD)-1)
groups((i+1)/2,:) = {sprintf('[A(find(strcmp({},%4s )==1)),A(find(strcmp({},%4s )==1))],/n',DD{i}, DD{i+1})}
to generate a cell array, each row of which would look like
[A(find(strcmp({}, SFG )==1)),A(find(strcmp({}, SFG )==1))],
where two consecutive name roots are to be grouped. The reason is that the roots are followed without spaces by numerical characters (eg "SFG3") which I have to manually enter after each root in each row above, then execute the grouping (the 'groups'). I need to do this as there are many name pair configurations that I need to use, some defying automation, and ever changing). What I need to do when I execute the for loop command, is to have the 'groups' ready at the command line for filling in the numbers, then execute, and not as answer which then I have to copy paste in the command line before filling in the numbers.So I would need the output from the for loop to figure as the next command to be executed, but only after I introduce all the no.
Please advise,


Why not
  • output the lines to an m-file
  • open the m-file in the editor
  • make the changes and save
  • run the m-file
  • keep the m-file as documentation
  • comment out lines and rerun the m-file as needed
A(find(strcmp({}, 'SFG')==1))
can be simplified to:
A(strcmp({}, 'SFG'))

Sign in to comment.

0 Answers