Remove number from a matrix within a for loop

This script outputs an 1x3 matrix (timeszmn2). I want to make it so that this script removes the 3rd number in this matrix within the 'for' loop. How can I do this?
I would assume that I need to make it so that zmndynarray2 doesn't have this third value?
zmn2 = zpoint';
d =[diff(zmn2) 0];
zmndynarray2 = [];
for i=1:(length(d)-1)
if d(i)*d(i+1)< 0 && d(i+1) > 0
zmndynarray2 = [zmndynarray2 (i+1)];
end
end
zmn2 = zpoint(zmndynarray2)
timeszmn2 = times(zmndynarray2)

4 comentarios

It is not obvious to me that the output would be a vector of length 3?
It looks to me as if you could probably get the locations using strfind() . strfind() is only documented for character matches, but it is not restricted to character matches. For example,
s = sign(d);
strfind(d(1:end-1) < 0 & d(2:end) > 0)
or you could test more directly on zmn2(1:end-1) in relationship to zmn2(2:end)
Also kind of looks like you are trying to do a findpeaks() kind of operation.
Elijah L
Elijah L el 19 de Sept. de 2020
I think what I am trying to do is narrow my criteria for what zmndynarray2 is.
For example, this is the graph I'm generating. I want to narrow my criteria so that "false minima" (e.g. the third point) are not detected.
Walter Roberson
Walter Roberson el 19 de Sept. de 2020
Have you considered findpeaks of the negative of the data ?
Elijah L
Elijah L el 19 de Sept. de 2020
Yes, I know I could easily use findpeaks or islocalmin but I would like to use a for loop as my algorithim

Iniciar sesión para comentar.

Respuestas (1)

Gaurav Garg
Gaurav Garg el 21 de Sept. de 2020
Hey Elijah,
You can replace the third element by [ ] in the script.
Example -
a = [1 2 3];
a(3)
a(3) = [ ]
What you would get is -
ans =
1 2

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Preguntada:

el 18 de Sept. de 2020

Respondida:

el 21 de Sept. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by