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);
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
>>
--