Pass the content of a variable to a .bat file from matlab
1 次查看(过去 30 天)
显示 更早的评论
Sorry, I have a new problem. I have this char variable: name='file.pdf';
when I do !test name
I see in the file test.bat "name", that is the container of the variabile but not the content of the variable.....I need to pass the content name.pdf to the file test.bat.
How can I resolve?? How cas I pass the string name.pdf to the .bat?
0 个评论
回答(1 个)
dpb
2016-2-13
编辑:dpb
2016-2-14
Use system instead for command form to evaluate variables in building the command string. ! ("Bang") interprets everything after it as character string so doesn't (as you've discovered) evaluate the variable before passing it to the OS.
>> f='c*.m'; % selected list of m-files in variable
>> [~,res]=system(['dir /b ' f]) % do a command; "dir" in the example...
res =
categorizeDesignated.m
currenteval.m
>>
ADDENDUM
Just do it again...
system(['report.bat ' res])
Or, more likely you'd want in real life something like
system(['report.bat <dir /b ' f])
Build the string that are going to submit just as you would any other string in Matlab; the limitation is that must(*) use the functional form instead of the bang operator to get a variable interpreted.
() without resort to evil *eval, which route I'm not going to suggest...albeit under some circumstances it is useful.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!