現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
0 投票
Please help!!!
a lok = sym('alok%d%d', [3 5 1]) % the piece of code and the error is below
??? Error using ==> sym.sym>createCharMatrix at 2480
Matrix syntax can only create vectors and matrices.
Error in ==> sym.sym>convertCharWithOption at 2439
s = createCharMatrix(x,a);
Error in ==> sym.sym>tomupad at 2195
S = convertCharWithOption(x,a);
Error in ==> sym.sym>sym.sym at 123
S.s = tomupad(x,a);
採用された回答
Walter Roberson
2011 年 10 月 22 日
0 投票
You cannot use that syntax to create a 3D symbolic matrix.
I note that you only have two %d in your symbol format, so I am not sure what you want to have happen for the third index?
8 件のコメント
Alok
2011 年 10 月 22 日
hello walter, thanks for replying, I am sorry for missing 1 %d and is there any way to generate 3D symbolic matrix ?
Walter Roberson
2011 年 10 月 22 日
The method I give in a previous answer might be suitable for your purpose:
http://www.mathworks.com/matlabcentral/answers/2521-creating-vector-of-symbols
Alok
2011 年 10 月 22 日
Oh thanks man,
I forgot about ndgrid, thanks again buddy, now my solver can be fully developed :)
Alok
2011 年 10 月 22 日
according to your note that you referred, will it help in 2011a version ?
Walter Roberson
2011 年 10 月 22 日
2011a and 2011b can use sym('pattern', [m n]) but that syntax does not extend to 3 or more dimensions.
Alok
2011 年 10 月 23 日
hello walter,
I tried to apply the code which you suggested, it was quite nice but it is giving me the following error, is it possible for you to look into the errors ?
>> P = 10; Q = 10; R = 10;
[ x, y, z ] = ndgrid( 1 : P, 1 : Q, 1 : R );
>> A = reshape( cellfun( @sym, strcat( 'A', cellstr( num2str( x( : ) ) ), cellstr( num2str( y( : ) ) ), cellstr( num2str( z( : ) ) ) ), 'Uniform', 0 ), P, Q, R );
??? Error using ==> sym.sym>convertExpression at 2547
Error: Unexpected 'integer' [line 1, col 3]
Error in ==> sym.sym>convertChar at 2458
s = convertExpression(x);
Error in ==> sym.sym>convertCharWithOption at 2441
s = convertChar(x);
Error in ==> sym.sym>tomupad at 2195
S = convertCharWithOption(x,a);
Error in ==> sym.sym>sym.sym at 111
S.s = tomupad(x,'');
Walter Roberson
2011 年 10 月 23 日
Ah, I didn't allow for multiple digits in the range. That's a bit of a nuisance.
Warning: this code will not work properly if you attempt to use a dimension of 0.
Pd = ceil(log10(P+1)); Qd = ceil(log10(Q+1)); Rd = ceil(log10(R+1));
Pf = sprintf('%%0%dd', Pd); Qf = sprintf('%%0%dd', Qd); Rf = sprintf('%%0%dd', Rd);
A = reshape( cellfun( @sym, strcat( 'A', cellstr(num2str(x(:),Pf)), cellstr(num2str(y(:),Qf)), cellstr(num2str(z(:),Rf)) ), 'Uniform', 0 ), P, Q, R );
This will add leading 0's to the values that are shorter.
The above code does not use any separation between the indices. If you want something such as an underscore, put it before the close-quote in Pf and Qf (but not in Rf).
If you want a separator _and_ you want the numbering to be as short as fits rather than using leading 0's, then you would not need Pd, Qd or Rd, and you would use
Pf = '%-d_'; Qf = '%-d_'; Rf = '%-d';
I think. I'd want to test that out to be safe (unfortunately my server is still unreachable these days.)
Alok
2011 年 10 月 29 日
Hello walter, I checked your solution after a while, could you please explain me, what is x(:), y and z, in the reshape function ?
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Common Operations についてさらに検索
タグ
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
