Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Conversion to cell from char is not possible

94 views
Skip to first unread message

Katarzyna

unread,
Apr 6, 2013, 7:00:08 AM4/6/13
to
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 '};
for halftone_number=-57:39
frequency(halftone_number-min_note_distance+1) = 440*power(2, halftone_number/12);
end;

for octave_number=0:7
for halftone_in_octave=1:12
str=base_name{halftone_in_octave}
name(octave_number*12+halftone_in_octave) = sprintf('%s%d', cell2str(base_name(halftone_in_octave)),octave_number);
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.

Katarzyna

unread,
Apr 6, 2013, 7:01:07 AM4/6/13
to

dpb

unread,
Apr 6, 2013, 4:15:25 PM4/6/13
to
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
>>

--
0 new messages