A problem about the lost of ' when I start matlab function using command with string as input argument.

조회 수: 1 (최근 30일)
I have a function called CMDEntryExitSuperColoc, with a file path string as input.
In the 1st attempt, I could run this function immediately as a new instance of Matlab by input following into command window:
%%%%%%%%%%
system('matlab -r CMDEntryExitSuperColoc(''D:\QMDownload\SuperColocParaImport1.txt'')')
%%%%%%%%%%
In a 2nd attempt, I need automatically restart computer and run this function by SchTasks. I do it as follows:
%%%%%%%%%%
taskname = 'SuperColocRescue';
runfile = ['C:\Program Files\MATLAB\R2016a\bin\matlab.exe -nosplash -nodesktop -minimize -r CMDEntryExitSuperColoc(''D:\QMDownload\SuperColocParaImport1.txt'')'];
frequency = 'ONCE';
starttime = '21:45';
system(['schtasks /create /tn "',taskname,'" /tr "',runfile,'" /sc ',frequency,' /st ',starttime,' /f']);
!shutdown /f /r /t 1
%%%%%%%%%%
This is what I got:
%%%%%%%%%%
To get started, type one of these: helpwin, helpdesk, or demo.
For product information, visit www.mathworks.com.
CMDEntryExitSuperColoc(D:\QMDownload\SuperColocParaImport1.txt)
|
Error: Unexpected MATLAB operator.
%%%%%%%%%%
It seems that the ' in the system('matlab... command works, and the function execute directly and siilently without the explicit command information showing on scrren, But the system(['schtasks... commands has a additional interpration procedure as indicated by the explicit CMDEntryExitSuperColoc(D:\QMDownload\SuperColocParaImport1.txt) in the command windows once initialized. However, the ' was lost, and it is no longer a string.
Dose the ' loss caused by Matlab or Windows Task scheduler?
Is there a smart way to input strings without the use of ' with system(['schtasks... command?
Just now I come up with an idea. Convert the path string to numbers, and use,this number as input to avoid ' useage. Then inside the function convert back to string. How to do it?
  댓글 수: 3
raym
raym 2017년 5월 6일
I have '' '' in the last second lines, so the blank is not worry. Earlier if I do not have '', its exactly what you say. Next I may generate a bat or vbs and schedule it instead.
raym
raym 2017년 5월 6일
Even if i use matlab to replace the path, the results is the same. ' was lost

댓글을 달려면 로그인하십시오.

채택된 답변

raym
raym 2017년 5월 6일
편집: raym 2017년 5월 6일
Solved by using the ASCII number matrix as input: such as CMDEntryExitSuperColoc([23,54,76,98,23,46,68,89,23])
mfileFolderMat = uint8(mfileFolder);
mfileFolderAscListStr = '';
for i = 1 : length(mfileFolderMat)
mfileFolderAscListStr = [mfileFolderAscListStr,num2str(mfileFolderMat(i)),','];
end
mfileFolderAscListStr(end) = '';
mfileFolderAscListStr = ['[',mfileFolderAscListStr,']'];
runfile = ['C:\Program Files\MATLAB\R2016a\bin\matlab.exe -nosplash -nodesktop -minimize -r CMDEntryExitSuperColoc(',mfileFolderAscListStr,')'];
function CMDEntryExitSuperColoc(mfileFolder)
if ~nargin
paraFolder = uigetdir('','Choose a folder containing only your parameter text files');
else
if ischar(mfileFolder)
paraFolder = mfileFolder;
elseif isnumeric(mfileFolder)
paraFolder = char(mfileFolder);
end
end
...
end

추가 답변 (1개)

Walter Roberson
Walter Roberson 2017년 5월 6일
system('matlab -r CMDEntryExitSuperColoc(''''D:\QMDownload\SuperColocParaImport1.txt'''')')
  댓글 수: 1
raym
raym 2017년 5월 6일
편집: raym 2017년 5월 6일
As I said,
system('matlab...
already works.
The loss of ' only take place for:
system(['schtasks....
And even for
system(['schtasks...,
I tried double the '','''', they just do not work.
No matter hoe many ' you use, all of them will be lost after schtasks.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by