필터 지우기
필터 지우기

facing problem in loop

조회 수: 2 (최근 30일)
Ali Asghar
Ali Asghar 2019년 8월 1일
편집: Bob Thompson 2019년 8월 1일
Dear
I am facing problem in below program.....
buttLoop3 is data signal having 30000x4 values
I want to find zero crossing on buttLoop3 in such a way that ti(k) return values of four different signal crossing zero value in 4 columns.....
for i = 1:4
y(i) = buttLoop3(:,i) ; % filtered signal 7:05pm 31-7-19
zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0); % Returns Approximate Zero-Crossing Indices Of Argument Vector
xi = zci(y(i) ); % zero crossing indices command
for k = 1:numel(xi)-1
ti(k) = interp1(y(i)([xi(k) xi(k)+1]), t([xi(k) xi(k)+1]), 0); % Interpolate To Find ‘t’ At ‘y=0 ’
end
end
  댓글 수: 8
Bob Thompson
Bob Thompson 2019년 8월 1일
편집: Bob Thompson 2019년 8월 1일
The new error is with this: y(i)([xi(k) xi(k)+1]).
If we simplify the second index, you having something of the form y(a)(b), which Matlab is not able to make sense of. The use of parentheses indicates that you are looking to call the entire element indicated by the values within the index, and so you can only use () indexing as the final index call. If you have a cell array, which can contain other matrices, it is possible to call the contents of a cell with curly braces {}, and then call elements within. If your y variable is a cell array, then the calling would look like this, y{a}(b). Notice that the paretheses are around the last index being called.
Without knowing what any of your variables are, or what exactly you're trying to do with this line, I cannot give you an exact solution on how to fix it. I can guess from the use of interp1 command that you have simply forgotten to include a comma after y(i), because interp1 requires three inputs, and were not intending to create a double index at all. If that is not the case, however, I suggest making the necessary adjustments to your indexing of y so that you are properly calling the elements.
Unfortunately, I cannot fully guess as to what your third input should be for interp1, because you only have two listed. If you know however, you should enter them in the order of interp1(X,Y,x1), where X is the independant variable array, Y is the dependant variable array, and x1 is the independant value you would like to interpolate to.
Guillaume
Guillaume 2019년 8월 1일
Note that the first comment by Walter had already pointed out that the interp line was invalid syntax.
Once that syntax error is fixed, the program will still not run since as also pointed by Walter:
y(i) = something with more than 1 element
is a runtime error.
As Walter said, using y everywhere instead of y(i) would solve both problems.
Also, the usefulness of the creation of the anonymous function inside the loop is questionable as it is used only once immediately after being created. May as well use the expression directly on y and not bother with the function call... or create the function just once outside the loop.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by