a length of number times to a function
2 次查看(过去 30 天)
显示 更早的评论
Hi everyone, this code is simple about I have a length number, I create a for loop for each number multiplies to a function, but the error is 'Unable to perform assignment because the indices on the left side are not compatible with the size of the
right side.' However, I tested each number times to function, the coide run. Please help me
N = [2 4 8 16 32];
b = 1./N;
for i = numel(b);
ye(i) = b(i)*(conv(ecg,h));
figure (4);
subplot(3,2,i+1);
stem(ye(i));
subplot(3,2,1);
stem(ecg);
end
0 个评论
采纳的回答
Rik
2022-2-15
Apparently conv(ecg,h) returns a vector, meaning that you can't store it in ye(i).
My guess would be that you would be willing to use a cell array for ye instead.
Without your variables it is difficult to test your code and to see what you mean.
N = [2 4 8 16 32];
b = 1./N;
ye=cell(size(b));
figure(4);
for n = 1:numel(b)
ye{n} = b(n)*(conv(ecg,h));
subplot(3,2,n+1);
stem(ye{n});
end
subplot(3,2,1);
stem(ecg);
2 个评论
Walter Roberson
2022-2-15
ecg and h do not change inside the loop. You could compute the result of the conv before the loop and use that.
After that, it would be obvious that each ye is a scaled version of the result of the conv. Is there any point in storing those results separately when you could just store the unscaled results and the scale factors and use those to recreate the data if you need it later?
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Octave 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!