Unable to sort symbolic variables in matlab

2 ビュー (過去 30 日間)
Aftab Ahmed Khan
Aftab Ahmed Khan 2016 年 2 月 24 日
コメント済み: Aftab Ahmed Khan 2016 年 2 月 24 日
There is a an issue in one section of my code. Let I have this symbolic equation. When i use the coeffs function like this it gives me the right coefficients and variables.
eq=(10219275*P10_10)/2097152 - P10_9/10 - P9_10/10
[a,b]=coeffs(eq);
a =
[ -1/10, 10219275/2097152, -1/10]
b =
[ P10_9, P10_10, P9_10]
but i want it to return me the variables and its coefficients in this order. How can i go about this rearrangement.
b =
[ P9_10, P10_9, P10_10]
Please help me.

採用された回答

Star Strider
Star Strider 2016 年 2 月 24 日
You can tell coeffs the order in which you want the coefficients returned:
syms P10_9 P10_10 P9_10
eq=(10219275*P10_10)/2097152 - P10_9/10 - P9_10/10
[a,b]=coeffs(eq, [P9_10, P10_9, P10_10])
a =
[ -1/10, -1/10, 10219275/2097152]
b =
[ P9_10, P10_9, P10_10]
  4 件のコメント
Walter Roberson
Walter Roberson 2016 年 2 月 24 日
Sort order is first by the number after 'P' and before the '_', and secondarily by the number after the '_'
Aftab Ahmed Khan
Aftab Ahmed Khan 2016 年 2 月 24 日
Well, i have managed to do it in another way found on the internet. Thanks once again.

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 2 月 24 日
Use http://www.mathworks.com/matlabcentral/fileexchange/10959-sort-nat--natural-order-sort a "natural sort" on the output of symvar() to get the order you want to do the sorting in, and then pass the sorted result as the second parameter of coeffs

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by