d_processor
d_processor

Reputation: 11

sprintf function: not working in octave the way it does for MATLAB

I need to call another commanline tool using octave .m files as wrapper. In following piece of code, it give eroor in line 'Detector'. It run quite nicely on Matlab but now I need to do it for octave. The documentation of Octave doesn't talk much about multi-line sprintf. Can anybody share solution to deal with such situations.

%s =sprintf(...
s =sscanf(...
[...
'                                                                   \n'...
'                                                                   \n'...
'Detector {                                                         \n'...    
'   [Plane: a_x(%f,%f,%f) a_y(%f,%f,%f) center(%f,%f,%f)]           \n'...
'   x1=%f  x2=%f  nx=%d                                             \n'...
'   y1=%f  y2=%f  ny=%d                                             \n'...
'   n_x_sub=%d n_y_sub=%d                                           \n'...        
                                                                                  \n'...
'   %s                                                              \n'...    
'}                                                                  \n'...
'                                                                   \n'...
Beam                                                            \n'...  
'   start(%f,%f,%f)                                                 \n'...
'   %s                                                              \n'...
'   %s                                                              \n'...
'   %s                                                              \n'...
'}                                                                  \n'...
'                                                                   \n'...    
'Commands {                                                         \n'...
'   no_noise                                                        \n'...
'}                                                                  \n'...
],...
eu(1),eu(2),eu(3),...
ev(1),ev(2),ev(3),...
a(1)-d*ew(1),...
a(2)-d*ew(2),...
a(3)-d*ew(3),...
-(uoff+0.5)*par.du,...
(par.nu-uoff-0.5)*par.du,...
par.nu,...
-(voff+0.5)*par.dv,...
(par.nv-voff-0.5)*par.dv,...
par.nv,...
par.up,...
par.up,...
CT_scale,...
a(1),...
a(2),...
a(3),...
keV,...
kV,...
mAs);

Upvotes: 0

Views: 792

Answers (1)

juliohm
juliohm

Reputation: 3779

There are many possibilities for handling multi-line strings in GNU Octave. Take the following as one of them:

sprintf("                     \
This is the first line\n      \
and this is the second\n      \
The square root of %d is %d\n \
", 4, 2)

The \ character is the string breaker, you have to use it whenever you desire to continue the string on the next script line.

Upvotes: 0

Related Questions