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

采纳的回答

Rik
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 个评论
Tu Nguyen
Tu Nguyen 2022-2-15
Thank you, do you have an email? I will send you all the variable? Because I meet this eeror many times
Walter Roberson
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 CenterFile Exchange 中查找有关 Octave 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by