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 ExchangeCreating, 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