繁体   English   中英

sprintf函数:不能像使用MATLAB那样在倍频程中工作

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

我需要调用另一个使用八度.m文件作为包装器的命令工具。 在下面的代码中,它在“检测器”行中给出了错误。 它可以在Matlab上很好地运行,但是现在我需要将其设置为八度。 Octave的文档没有过多讨论多行sprintf。 任何人都可以共享解决方案来应对这种情况。

%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);

在GNU Octave中处理多行字符串有很多可能性。 将以下内容作为其中之一:

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

\\字符是字符串分隔符 ,每当需要在下一个脚本行中继续该字符串时,都必须使用它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM