Trouble using the system command with special characters

4 ビュー (過去 30 日間)
KCE
KCE 2021 年 10 月 19 日
コメント済み: KCE 2021 年 10 月 19 日
Hi,
I am having trouble using the system command to convert a group of png files (using the wildcard symbol) to a gif using ImageMagick, but within a MATLAB script.
Here is the code that is not working:
datenum = str2num(num);
system('convert −delay 65 −loop 0 [ea,'_',KXXX,'_',datenum(1:end-1),'*_',varplotted,'.png'] [ea,'_',KXXX,'_',datenum,'_',varplotted,'.gif']');
And here is the error when I type just the command in MATLAB interactive mode:
>> 'convert -delay 65 -loop 0 [ea,'_',KXXX,'_',datenum(1:end-1),'*_',varplotted,'.png'] [ea,'_',KXXX,'_',datenum,'_',varplotted,'.gif']'
'convert -delay 65 -loop 0 [ea,'_',KXXX,'_',datenum(1:end-1),'*_',varplotted,'.png'] [ea,'_',KXXX,'_',datenum,'_',varplotted,'.gif']'
|
Error: Invalid text character. Check for unsupported symbol, invisible character, or
pasting of non-ASCII characters.
Thanks!

回答 (2 件)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021 年 10 月 19 日
One ' sign is missing before 1st comma ","
datenum = str2num(num);
system('convert −delay 65 −loop 0 [ea','_',KXXX,'_',datenum(1:end-1),'*_',varplotted,'.png'] [ea,'_',KXXX,'_',datenum,'_',varplotted,'.gif']');
  1 件のコメント
KCE
KCE 2021 年 10 月 19 日
When I include this, the (new) error message I get is:
Invalid expression. When calling a function or indexing a variable, use parentheses.
Otherwise, check for mismatched delimiters.

サインインしてコメントする。


per isakson
per isakson 2021 年 10 月 19 日
編集済み: per isakson 2021 年 10 月 19 日
You try to call system() with a sequence of several input arguments and assumes that system() shall join these arguments to the command. system() doesn't work that way.
From the documentation of system
status = system(command) (and click command)
where command should be a scalar string or a character vector.
Thus you need to build ONE character vector (or string scalar), which comprises all parts of the command. Since your command is so long, I propose that you create three variables and finally concatenate them with horzcat().
cmd_1 = 'convert −delay 65 −loop 0 ';
file1 = [ea','_',KXXX,'_',datenum(1:end-1),'*_',varplotted,'.png'];
file2 = [ea,'_',KXXX,'_',datenum,'_',varplotted,'.gif'];
Before you concatenate them, each one must be a character vector. This code will throw several errors, but it's a beginning.

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by