facing problem in loop

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 comentarios

Walter Roberson
Walter Roberson el 1 de Ag. de 2019
y(i) = buttLoop3(:,i)
The right hand side is 30000 x 1. The left hand side is 1 x 1.
interp1(y(i)([xi(k) xi(k)+1])
y(i) is either a function call or an indexing. Neither one can be followed immediately by () indexing.
You could assign into y{i} and use
interp1(y{i}([xi(k) xi(k)+1])
However, there does not appear to be any benefit to using the y variable: just use y without indexing. If for some reason you need to work with individual y afterwards, then get the information out of buttLoop3.
Ali Asghar
Ali Asghar el 1 de Ag. de 2019
dear
below code shows error...
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]); % Interpolate To Find ‘t’ At ‘y=0 ’
end
end
Error: File: filtering2.m Line: 193 Column: 38
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
If possible write a complete program
Thank you
Bob Thompson
Bob Thompson el 1 de Ag. de 2019
You need a closing parentheses on the interp1.
ti(k) = interp1(y(i)([xi(k) xi(k)+1]));
Ali Asghar
Ali Asghar el 1 de Ag. de 2019
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])); % Interpolate To Find ‘t’ At ‘y=0 ’
end
end
Error: File: zerocrossing2.m Line: 6 Column: 17
()-indexing must appear last in an index expression.
Bob Thompson
Bob Thompson el 1 de Ag. de 2019
What is line 6? It's more helpful if you post the entire error message, including the line that indicates which line of code triggers the error.
Ali Asghar
Ali Asghar el 1 de Ag. de 2019
Sir
I posted entire error message which i get after run it.
although line 6 is ti(k) = interp1(y(i)([xi(k) xi(k)+1])); % Interpolate To Find ‘t’ At ‘y=0 ’
I request if u write the whole code so i can run it and find my mistake.
Thank you
Bob Thompson
Bob Thompson el 1 de Ag. de 2019
Editada: Bob Thompson el 1 de Ag. de 2019
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 el 1 de Ag. de 2019
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.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Etiquetas

Preguntada:

el 1 de Ag. de 2019

Editada:

el 1 de Ag. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by