MATLAB Answers

Sotiris
0

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

Asked by Sotiris
on 12 Apr 2011
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

  0 Comments

Sign in to comment.

Products

2 Answers

Answer by Walter Roberson
on 12 Apr 2011
 Accepted Answer

You mean something like,
dos(sprintf('xform -ry %1.0f -t %1.0f %1.0f %1.0f something.rad',deg,x,y,z))

  0 Comments

Sign in to comment.


Answer by Jason Ross
on 12 Apr 2011

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.

  0 Comments

Sign in to comment.