Azzera filtri
Azzera filtri

a length of number times to a function

1 visualizzazione (ultimi 30 giorni)
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

Risposta accettata

Rik
Rik il 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 Commenti
Tu Nguyen
Tu Nguyen il 15 Feb 2022
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 il 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?

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Interpolation in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by