How can I use a string as a function parameter?
4 次查看(过去 30 天)
显示 更早的评论
I'm reading a bunch of these strings from a .txt file, and I want to use these strings to make complex numbers.
i.e. I have a string mc = '(1., 0.)' and I want to use that as the parameters for the complex function so I get complex(1.,0.) or complex((1., 0.)).
UPDATE: I figured out that I can use the sscanf function, but I'm still wondering if there is a more efficient way of doing this.
0 个评论
回答(1 个)
Star Strider
2018-2-14
The easiest way is probably to use sscanf:
mc = '(1.2, 0.)';
mn = sscanf(mc, '(%f,%f)')';
mz = complex(mn(:,1), mn(:,2))
Experiment to get the result you want.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!