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

Esteban Fernandez
Esteban Fernandez 2015년 9월 8일
It is correct the logic of the algo?
Thank you very much
Stephen23
Stephen23 2015년 9월 11일
편집: Stephen23 2015년 9월 11일
@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.

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

 채택된 답변

Stephen23
Stephen23 2015년 9월 8일
편집: Stephen23 2015년 9월 8일

0 개 추천

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

Esteban Fernandez
Esteban Fernandez 2015년 9월 8일
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 2015년 9월 8일
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.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

제품

태그

아직 태그를 입력하지 않았습니다.

질문:

2015년 9월 8일

편집:

2015년 9월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by