Need help abt error.
古いコメントを表示
Here is my code. till the time the alto_dur and teb_dur are exactly same vectors, then there is no problem but if i make
alto_dur = [ 2*t t 2*t t 5*t]; and
treb_dur=[*t* t 2*t t 5*t]; I get error
??? Error using ==> plus Matrix dimensions must agree.
Error in ==> test at 38 final_song = cellfun(@plus, alto, treb, 'Uniform', 0); % Alto Tones and Treble tones are added
The code is here fs=8500; t=.18; % this t is used in duration as a multiple or single identity % Key Number and duration of each note %************************Alto************ alto_keys = [ 46 46 0 46 0]; alto_dur = [ 2*t t 2*t t 5*t]; %************************************
%******************Treeble*********************************** % It is high or acute part of the musical system
treb_keys=[56 56 0 56 0 ]; % Duration of ech note treb_dur=[2*t t 2*t t 5*t]; %********************************************
alto = cell(1, length(alto_keys)); % It will creat a cell array having one row and % columns equal to number of keys for i = 1:length(alto_keys) % The for loop continues till number of Keys alto{i} = adsr_note(alto_keys(i), alto_dur(i)); % Function adsr_note is called which calculates %tone for each key for the specified duration and apply ADSR Envolop on it. This tone is stored in % alto{i} end
treb = cell(1, length(treb_keys)); % It will creat a cell array having one row and % columns equal to number of keys for k = 1:length(treb_keys) % The for loop continues till number of Keys treb{k} = adsr_note(treb_keys(k), treb_dur(k)); % Function adsr_note is called which calculates %tone for each key for the specified duration and apply ADSR Envolop on it. This tone is stored in % treb{i} end
final_song = cellfun(@plus, alto, treb, 'Uniform', 0); % Alto Tones and Treble tones are added % Option Uniform or UniformOutput set to 0 (or false) means, that output from function will be stored in cell array
% Concatinating Tone Vectors tone = cat(2, final_song{:}); % It will concatinate arrays of final_song in a row. 2 means %row. If we will use 1, it will concatinate in a column
1 件のコメント
Wayne King
2011 年 9 月 28 日
Hi, it's hard to read your code above. If the error is occurring at
cellfun(), please give us the sizes of alto and treb
size(alto), size(treb)
採用された回答
その他の回答 (7 件)
Wayne King
2011 年 9 月 28 日
Hi, I don't have any problem running this code:
fs=8500; t=.18;
alto_keys = [ 46 46 0 46 0];
alto_dur = [ 2*t t 2*t t 5*t];
treb_keys=[56 56 0 56 0 ];
treb_dur=[2*t t 2*t t 5*t];
alto = cell(1, length(alto_keys));
for i = 1:length(alto_keys) alto{i} = adsr_note(alto_keys(i), alto_dur(i));
end
treb = cell(1, length(treb_keys));
for k = 1:length(treb_keys) treb{k} = adsr_note(treb_keys(k), treb_dur(k)); end
final_song = cellfun(@plus, alto, treb, 'Uniform', 0);
tone = cat(2, final_song{:});
with your adsr_note function. Maybe you have something left over in your workspace that is causing an error? Or maybe you're using a differnt version of adsr_note (perhaps you saved it in a different folder). Can you clear your workspace and try it?
Does
>>which adsr_note
return what you think it should?
Wayne
moonman
2011 年 9 月 28 日
Wayne King
2011 年 9 月 28 日
Can you just pad the shorter vectors with zeros to make them equal length with the longer ones. That way the vector addition will be defined.
fs=8500; t=.18;
alto_keys = [ 46 46 0 46 0];
alto_dur = [ 3*t t 3*t t 5*t];
treb_keys=[56 56 0 56 0 ];
treb_dur=[3*t t 3*t t 5*t];
alto = cell(1, length(alto_keys));
for i = 1:length(alto_keys) alto{i} = adsr_note(alto_keys(i), alto_dur(i));
end
treb = cell(1, length(treb_keys));
for k = 1:length(treb_keys) treb{k} = adsr_note(treb_keys(k), treb_dur(k)); end
alto = cellfun(@(x) [x zeros(1,length(treb{1})-length(alto{1}))], alto,'UniformOutput',false);
final_song = cellfun(@plus, alto, treb, 'Uniform', 0);
tone = cat(2, final_song{:});
fs=8500; t=.18;
alto_keys = [ 46 46 0 46 0];
alto_dur = [ 3*t t 3*t t 5*t];
treb_keys=[56 56 0 56 0 ];
treb_dur=[3*t t 3*t t 5*t];
alto = cell(1, length(alto_keys));
for i = 1:length(alto_keys) alto{i} = adsr_note(alto_keys(i), alto_dur(i));
end
treb = cell(1, length(treb_keys));
for k = 1:length(treb_keys) treb{k} = adsr_note(treb_keys(k), treb_dur(k)); end
alto = cellfun(@(x) [x zeros(1,length(treb{1})-length(alto{1}))], alto,'UniformOutput',false);
final_song = cellfun(@plus, alto, treb, 'Uniform', 0);
tone = cat(2, final_song{:});
moonman
2011 年 9 月 28 日
カテゴリ
ヘルプ センター および File Exchange で Structures についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!