How can I use a string as a function parameter?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Star Strider
el 14 de Feb. de 2018
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 comentarios
Ver también
Categorías
Más información sobre Characters and Strings en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!