Need help for addition of cells
显示 更早的评论
Here is portion ofmy code
alto = cell(1, length(keysa));
for i = 1:length(keysa) % The for loop continues till number of Keys
alto{i} = note(keysa(i), dura(i)); function is called
end
treb = cell(1, length(keyst));
for i = 1:length(keyst)
treb{i} = note(keyst(i), durt(i)); % function is called
end
Now what i want is that to make a final cell array in which treb{i} and alto{i} are added and stored one by one i mean
final{1}= treb{1}+alto{1}
final {2}= treb{2} +alto{2}
so final is addition of both two.
I tried this one but gave error
final=cell(1,length(keyst)
for k=1:length(keyst)
final{i}=alto(i)+treb(i);
end
采纳的回答
更多回答(5 个)
moonman
2011-9-21
6 个评论
Fangjun Jiang
2011-9-21
Walter forgot one right parenthesis in the first line. You can add it yourself.
Walter Roberson
2011-9-21
The first line needed a ')'. I have edited it in to place.
Walter Roberson
2011-9-21
Walter copied the line as-is from the original posting...
moonman
2011-9-21
moonman
2011-9-21
Walter Roberson
2011-9-21
length of treb and alto might be the same, but each of them is a cell array possibly containing a vector or matrix. Do the sizes of those agree?
Try this:
find(cellfun(@(A,T) ~(isequal(size(A),size(T)) || numel(A) == 1 || numel(T) == 1), alto, treb))
If any numbers are printed out, then they are each indices K such that alto{K} cannot be added to treb{K} because the sizes are different.
moonman
2011-9-21
0 个投票
1 个评论
Walter Roberson
2011-9-21
I am doing multiple things at the same time; I can't always notice and test and write a response within 8 minutes. :(
moonman
2011-9-22
2 个评论
moonman
2011-9-22
Walter Roberson
2011-9-22
Shrug. You never did indicate what you want the additions to mean, so I just followed your outline, which is not going to produce a single array suitable for using in soundsc()
If you are attempting to do additive synthesis of sound, then you need to define the time relationships between the various components.
If it happens that the alto and treb of each pair are to be played at the same time, but only one pair at a given time, and no pause between adjacent pairs, then you want
fullsound = horzcat(final{:});
and then soundsc(fullsound,fs);
If you get a dimension error when you try that, change the horzcat() to vertcat().
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!