a length of number times to a function

조회 수: 2 (최근 30일)
Tu Nguyen
Tu Nguyen 2022년 2월 15일
댓글: Walter Roberson 2022년 2월 15일
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