フィルターのクリア

Converting sym to string without 'matrix....' before

5 ビュー (過去 30 日間)
Marco
Marco 2013 年 9 月 26 日
コメント済み: Walter Roberson 2020 年 11 月 26 日
Hi,
I need some help to convert a symbolic array to string.
I tried with:
syms a b c
Array = [a b c];
string = char(Array);
but it returns
matrix([[a b c]]);
Is there a way to take only the string inside ? I need set it to take '[a b c]' as string.
Thanks

採用された回答

Wayne King
Wayne King 2013 年 9 月 26 日
Can you tell us the use case here, you just want to display it as a string?
One thing you can do is
syms a b c
Array = [a b c];
array_string = char(Array);
array_string([1:8, end-1:end]) = [];
  5 件のコメント
genevois pierre
genevois pierre 2020 年 11 月 25 日
if I want to execute a program in which at least one line contains matrix, an error comes ...
Is there no more convenient conversion from a symbolic (which is coming from solve) to a character vector than that using char ?
Walter Roberson
Walter Roberson 2020 年 11 月 26 日
No, there is no more convenient way.
Caution: char() of a symbolic expression gives a result which is not exactly a MATLAB expression, and which is not exactly a MuPAD expression either. You should only use char() of a symbolic expression for display purposes.
If you need to generate MATLAB code from a symbolic expression, use matlabFunction(), possibly followed by func2str()

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 11 月 7 日
In the case of symbolic row vectors:
['[', strjoin(arrayfun(@char, Array, 'uniform', 0),', '), ']']

カテゴリ

Help Center および File ExchangeAssumptions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by