Problem in syntax

3 次查看(过去 30 天)
Alok
Alok 2011-10-21
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
Walter Roberson 2011-10-22
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 个评论
Walter Roberson
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
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 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by