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. I need to raise the problem well, maybe for my bad english, the problem is not explain well. I will explain well
Thank you very much and sorry

7 件のコメント

Esteban Fernandez
Esteban Fernandez 2015 年 9 月 9 日
Some comments?? Thank you very much
dpb
dpb 2015 年 9 月 9 日
Sorry, the language difficulties of English clearly not being your first are making it difficult to follow the logic description.
It's likely easier to show the starting point and then the desired solution; that combined with the narrative may let others understand the problem to be solved.
Esteban Fernandez
Esteban Fernandez 2015 年 9 月 9 日
編集済み: Walter Roberson 2015 年 9 月 9 日
Sorry,
I am going to try to explain by other way.
I start with
W = [1 3
2 4
2 2
3 3
4 2
5 0];
Two columns and six rows.
I want to have:
  • when program find a “1” in column number one ( in the matriz, the program find a “1” in w(1,1),
  • If the number of cell (3,1) is higher than “1” and the difference is higher than “1”, then save this difference and continue evaluate next cells (3,2), (4,2)... till the programm find a number fewer than “1” in column two. In the example, the program find a number fewer “1” in (6,2)
  • Like i save differences in column one, the result must be the max difference till program find a fewer number in column two.
In the example :
  • Programm find “1” in column number one and first row (1,1)
  • I start comparing number in row number three and column one (3,1). If the number in cel (3,1) is higher than (1,1) and difference between this two numbers is >1 then next step, else i need compare cell (4,1) with (1,1).... In this example 2>1, so next step
  • If previous condition is satisfied, then i save the difference between (3,1) and (1,1)... In this example 2-1=1.
  • When program find a number fewer in column two, then i stop of calculate differences. In the example i stop of calculating differences from row number six because the program found 0<1 in column number two.
  • The table of differences:
differences =
1
2
3
4
  • I calculate the max difference that is equal to 4
  • The final result is:
w = [1 3 4
2 4 0
2 2 0
3 3 0
4 2 0
5 0 0]
Thank you very much and sorry for my English!
Esteban Fernandez
Esteban Fernandez 2015 年 9 月 10 日
Is it posible with vectorization? there are many bucles.
Thank you very much
Esteban Fernandez
Esteban Fernandez 2015 年 9 月 10 日
Someone know how can i start with correct logic? thank you very much
Stephen23
Stephen23 2015 年 9 月 10 日
編集済み: Stephen23 2015 年 9 月 10 日
Have a read of this question and answer, you might find something useful there:
BTW, do not use the term "cells" in MATLAB to refer to an element of an array, because MATLAB has a data class called "cell array", and "cell" refers only to an element of that data class.
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.

サインインしてコメントする。

 採用された回答

Thorsten
Thorsten 2015 年 9 月 10 日

1 投票

The first index you need is the row of the first occurrence of your desired number num in column 1 of W
num = 1;
ind1 = find(W(:,1) == num, 1, 'first');
The second index is the index of the first row where the second column in W is smaller than num
ind2 = find(W(:,2) < num, 1, 'first');
Than you take the maximum of the differences:
max(W(ind1+2:ind2, 1) - W(ind1, 1))

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGet Started with MATLAB についてさらに検索

タグ

タグが未入力です。

質問済み:

2015 年 9 月 9 日

編集済み:

2015 年 9 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by