Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Conversion to cell from char is not possible
Replies: 1   Last Post: Apr 6, 2013 4:15 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
dpb

Posts: 8,295
Registered: 6/7/07
Re: Conversion to cell from char is not possible
Posted: Apr 6, 2013 4:15 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 4/6/2013 6:01 AM, Katarzyna wrote:
> Hi,
> I have a problem with this code:
> frequency = zeros(1,1+max_note_distance - min_note_distance);
> name = {1,1+max_note_distance - min_note_distance};
> base_name = {'C ' 'C#' 'D ' 'D#' 'E ' 'F ' 'F#' 'G ' 'G#' 'A ' 'A#' 'B '};


...
...[variable names below shortened for legibility]...

> for on=0:7
> for ho=1:12
> %str=base_name{ho} % unused???
> name(on*12+ho) = sprintf('%s%d', cell2str(base_name(ho)),on);
>end;
> end;
>
> cell2str function is there:
> http://www.mathworks.com/matlabcentral/fileexchange/3369-techniques-of-model-based-control/content/cell2str.m
>
> Matlab gives me the following error message:
> Conversion to cell from char is not possible. It is something wrong with
> sprintf function i guess. Please help me fix it.


What's the point of cell2str()???? It seems to be something specific
for the related project that's expecting a transfer function
represenation for a MIMO/SISO model which you're certainly not providing it.

It would certainly make it easier as well to provide the error in
context as ML gave it rather than an abbreviated version...but, in
general, yes, sprintf() doesn't work w/ cell strings but char() or {} to
dereference is generally all that is needed.

Well, let's poke around at the command line and see what's going on...

>> name = {'C ' 'C#' 'D ' 'D#' 'E ' 'F ' 'F#' 'G ' 'G#' 'A ' 'A#' 'B '};
>> on=0;ho=1; sprintf('%s%d', name(ho),on)

??? Error using ==> sprintf
Function 'sprintf' not defined for variables of class 'cell'.

And, indeed, that's what commented on above, precisely. Two possible
solutions--


>> sprintf('%s%d', name{ho},on) % using curlies
ans =
C 0
>> sprintf('%s%d', char(name(ho)),on) % or char() on the cell
ans =
C 0
>>

--




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.