Clear Filters
Clear Filters

error using system -- "Command argument must be either a nonmissing scalar string or a character row vector. "

21 views (last 30 days)
I donwloaded open source code that enables me to run Qspice from the command line and directly use its data in the MATLAB script. However, I get an error in the this section that I cannot understand:"Command argument must be either a nonmissing scalar string or a character row vector."
c = cmdsep; //this works in my version of MATLAB (2023b).
cmd_str = [
'path ',QspicePath,...
c,...
'QUX -Netlist "',Qpath.qsch,'"'
];
[status,Qpath.cir] = system(cmd_str)
it seems the syntax of the assembled path/file to run is incorrect, but I don't know what it needs to be.
The assembled cmd_str is:
cmd_str =
1×6 string array
"path " "C:\Program Files\QSPICE\" "&&" "QUX -Netlist "" "C:\Users\jorge.rive\OneDri" """
The error I get when
system(cmd_str)
runs is:
Error using system
Command argument must be either a nonmissing scalar string or a character row vector.
Thank you in advance for the help.
Jorge
  3 Comments

Sign in to comment.

Accepted Answer

Stephen23
Stephen23 on 10 Jan 2024
Edited: Stephen23 on 10 Jan 2024
"it seems the syntax of the assembled path/file to run is incorrect"
True, it is a 1x6 string array.
"but I don't know what it needs to be."
The error message tells you that it needs to be a scalar (i.e. 1x1) string or a character vector.
The basic problem is that you concatenated lots of text together without paying attention to what types they are. As you have found out, in general that won't work:
  • one or more character vectors only will be concatenated into one character vector (this seems to be what you expected but did not confirm by checking your data).
  • one or more string arrays with zero or more char vectors will be concatenated into an string array (with as many elements as the input string arrays have... plus one element for each char vector). This is what your data actually are.
Note that even just one string will completely change the concatenation behavior.
A simple and reliable approach is to use SPRINTF instead, e.g.:
cmd_str = sprintf('%s',...
'path ',QspicePath,...
c,...
'QUX -Netlist "',Qpath.qsch,'"');
It will accept any text type and return a character vector (just as that error message tells you).
  4 Comments
Voss
Voss on 10 Jan 2024
Edited: Voss on 10 Jan 2024
"I don't understand why the concatenated strings were still an array of strings instead of a "single" one."
@Jorge: What you were using (the square brackets, []) was array concatenation, which works the same for string arrays as it does for numeric arrays (and arrays of any class):
str1 = "hello"; % scalar string
str2 = "world"; % scalar string
[str1, str2] % 1x2 string array
ans = 1×2 string array
"hello" "world"
n1 = 1; % scalar double-precision floating-point number (commonly called a "double")
n2 = 2; % scalar double
[n1, n2] % 1x2 double array
ans = 1×2
1 2
However, if you want to concatenate multiple strings into a single string, you need to perform string concatenation, which you can do using the plus (+) operator:
str1 + str2
ans = "helloworld"
str1 + " " + str2
ans = "hello world"
or using a function for that purpose, e.g.:
strcat(str1,str2)
ans = "helloworld"
strcat(str1," ",str2)
ans = "hello world"
join([str1,str2]," ")
ans = "hello world"
"I don't understand what char actually does!"
The char function converts the input to a character array (not a string),
char(str1) % note the single quotes in the result -> character array, not a string
ans = 'hello'
appending spaces as necessary and adding dimensions as necessary for non-scalar string array input:
str1 = "hell"; % using a shorter string to see the space-padding char does
str = [str1;str2] % 2x1 string input
str = 2×1 string array
"hell" "world"
char(str) % 2x5 char output
ans = 2×5 char array
'hell ' 'world'
str = [str1,str2] % 1x2 string input
str = 1×2 string array
"hell" "world"
char(str) % 1x5x2 char output
ans = 1×5×2 char array
ans(:,:,1) = 'hell ' ans(:,:,2) = 'world'
str = cat(3,str1,str2)+reshape(1:12,3,[]) % 3x4x2 string input
str = 3×4×2 string array
str(:,:,1) = "hell1" "hell4" "hell7" "hell10" "hell2" "hell5" "hell8" "hell11" "hell3" "hell6" "hell9" "hell12" str(:,:,2) = "world1" "world4" "world7" "world10" "world2" "world5" "world8" "world11" "world3" "world6" "world9" "world12"
char(str) % 3x7x4x2 char output
ans = 3×7×4×2 char array
ans(:,:,1,1) = 'hell1 ' 'hell2 ' 'hell3 ' ans(:,:,2,1) = 'hell4 ' 'hell5 ' 'hell6 ' ans(:,:,3,1) = 'hell7 ' 'hell8 ' 'hell9 ' ans(:,:,4,1) = 'hell10 ' 'hell11 ' 'hell12 ' ans(:,:,1,2) = 'world1 ' 'world2 ' 'world3 ' ans(:,:,2,2) = 'world4 ' 'world5 ' 'world6 ' ans(:,:,3,2) = 'world7 ' 'world8 ' 'world9 ' ans(:,:,4,2) = 'world10' 'world11' 'world12'

Sign in to comment.

More Answers (1)

Hassaan
Hassaan on 10 Jan 2024
c = cmdsep; % This works in MATLAB 2023b
QspicePath = 'C:\Program Files\QSPICE\'; % Example path, replace with actual
Qpath.qsch = 'C:\Path\To\Your\Netlist.qsch'; % Replace with your actual netlist file path
% Construct the command string
cmd_str = strjoin([
'path ', QspicePath,
c,
'QUX -Netlist "', Qpath.qsch, '"'
], '');
% Execute the command
[status, Qpath.cir] = system(cmd_str);
% Check status and output
disp(status);
disp(Qpath.cir);
  1. strjoin is used with an empty delimiter '' to concatenate all the parts of the command into a single string.
  2. Ensure that QspicePath and Qpath.qsch contain the correct paths for your QSPICE installation and netlist file, respectively.
  3. The system command is then executed with cmd_str as a single concatenated string.
This should resolve the error and allow the command to be executed properly. However, make sure that the paths and command syntax are correct for your specific QSPICE setup and environment.
---------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
Professional Interests
  • Technical Services and Consulting
  • Embedded Systems | Firmware Developement | Simulations
  • Electrical and Electronics Engineering
Feel free to contact me.

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Tags

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!