Using dos command, how can I change the content of the quotes on every loop

조회 수: 1 (최근 30일)
Hello team,
i want to use the dos command for a program. I need to change the quotes on every loop in order to avoid increasing the size of the program.
Example
dos('xform -ry %1.0f -t %1.0f %1.0f %1.0f something.rad',deg,x,y,z)
This is what I want to create. How can I do this using Dos command, or do you have anything else to suggest.
Thank you in advance
Sotiris Papantoniou

채택된 답변

Walter Roberson
Walter Roberson 2011년 4월 12일
You mean something like,
dos(sprintf('xform -ry %1.0f -t %1.0f %1.0f %1.0f something.rad',deg,x,y,z))

추가 답변 (1개)

Jason Ross
Jason Ross 2011년 4월 12일
You could try building the command string in a loop outside the dos() call and then make the calls.
A simple example is as follows:
A=[1 2 3 4 5];
for i=1:1:5
Ai = num2str(A(i));
cmdstr = ['echome', ' ', Ai];
dos(cmdstr);
end
Output looks like the following, but the number passed as an argument changes from 1 to 5:
c:\temp>echo "my argument is " 1
"my argument is " 1
ans =
0
Notes:
  1. You will likely want to do something with the result of the dos() command or check the return status, e.g. [status, result] = dos(command).
  2. "echome" is a batch file in the current working directory that contains "echo "my arg is" %1". If you wanted to expand out to four arguments, you would add %2 %3 %4 to it. You would call "xform", but might want to use a toy example like this to get the formatting figured out first if xform takes a while to run.

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by