Problem in syntax

3 views (last 30 days)
Alok
Alok on 21 Oct 2011
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);

Accepted Answer

Walter Roberson
Walter Roberson on 22 Oct 2011
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 Comments
Walter Roberson
Walter Roberson on 23 Oct 2011
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 on 29 Oct 2011
Hello walter, I checked your solution after a while, could you please explain me, what is x(:), y and z, in the reshape function ?

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!