The Math Forum

Search All of the Math Forum:

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

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

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 ]

Posts: 9,850
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;
> cell2str function is there:
> 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

>> 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]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.