a length of number times to a function
2 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Rik
on 15 Feb 2022
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 Comments
Walter Roberson
on 15 Feb 2022
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?
More Answers (0)
See Also
Categories
Find more on Octave in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!