'Taskill in matlab by PID

I have the following matlab code to close a cmd window

pid = 21324
if ispc
    cmd = sprintf('taskkill /PID %d', pid);
else
    cmd = sprintf('kill %d', pid);
end
system(cmd)

But I get the following error

Error using TaskKill Too many input arguments.
MATLAB:TooManyInputs Error: Too many input arguments.

I tried to find examples and documentation but it is supposed to work

I am using matlab R2018b and windows



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source