How to Pass String to System Call

2 次查看(过去 30 天)
When trying to call a c program externally, I'm having a compiling error inside Matlab when trying to use fprintf to print out two float arrays that have been converted to type str through num2str.
I was forced to use fprintf since strcat removes spaces so instead of executing 'Emerge.exe (float variables)', it will output 'Emerge.exe(float variables)' with no space included in the DOS console.
Using fprintf combines the strings and includes the necessary spacing, but Matlab returns the error:
Error using system Argument must contain a string.
Error in GAforSharks (line 28) [~, scores] = system(fprintf(1,'%s %s %s ',program,num2str(population((n*2)-1,:)),num2str(population(n*2,:))),'-echo');
I used isstr() on the "fprintf(1,'%s %s %s ',program,num2str(population((n*2)-1,:)),num2str(population(n*2,:)))" to make sure it was type string and it is not, but I need to use fprintf to print the string and preserve the spacing. So I'm not sure how to go about passing a string with spaces to the system function.
TL;DR - Help please, I need to send the program name as well as an array of integers to console.
Regards,
Jessie S.

回答(1 个)

David Sanchez
David Sanchez 2014-12-11
Use horzcat instead of strcat. horzcat keeps the blank spaces.
help horzcat

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by