Sorry, all problem statement is wrong, and I do not know how to delete these questions, because I do not want to confuse people who may read it.

2 Kommentare

Esteban Fernandez
Esteban Fernandez am 8 Sep. 2015
It is correct the logic of the algo?
Thank you very much
Stephen23
Stephen23 am 11 Sep. 2015
Bearbeitet: Stephen23 am 11 Sep. 2015
@Esteban Fernandez: please never delete your question like this. This is a community forum, and the answers are only useful when you leave your question text intact. We are all volunteers and we write answers that everyone can read and possibly find useful. We are not your personal tutors or code fixing service. We are not here to offer you and only you this answer, it was intended to be for all users who might find the topic interesting or have similar problems. When you selfishly delete the question than you have abused the purpose of this forum and our own time and effort.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Stephen23
Stephen23 am 8 Sep. 2015
Bearbeitet: Stephen23 am 8 Sep. 2015

0 Stimmen

Your code is much more complicated than it needs to be: in particular multiple nested loops are not good practice, the indexing could be much more helpful, many simple logical operations should be vectorized, and you don't use any functions to help you (e.g. diff, any). Here is how I implemented the first three steps, you can easily figure out the last two steps.
M = [2;3;0;1;2;0;1;0;1;4];
% 1
idx = 2==M;
for k = find(idx')
% 1
idx(k) = all(3~=M(min(end,k+(1:3))));
% 2
idx(k) = idx(k) && any(0<=diff(M(k+3:end)));
% 3
idx(k) = idx(k) && any(1<=diff(M)); % not clearly defined!
end
This creates the following vector, which is true for the single 2 which passes the first three steps:
idx =
0
0
0
0
1
0
0
0
0
0
Actually I stopped at the third step because it is not clear what is required here: it seems that step 2 is a subset of step 3, so you only need to test step 3. If this is not the case then you need to specify these steps much more clearly.

2 Kommentare

Esteban Fernandez
Esteban Fernandez am 8 Sep. 2015
Thank you very much!!
i am going to study your code and i am going to try to have the last steps.
Thank you very much!!
Stephen23
Stephen23 am 8 Sep. 2015
My Pleasure. I am happy to help if you have any questions about how it works (please add comments to this answer). You should read about array indexing and code vectorization in MATLAB, which will help you to understand that code.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Hilfe-Center und File Exchange

Produkte

Tags

Noch keine Tags eingegeben.

Community Treasure Hunt

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

Start Hunting!

Translated by