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 Kommentare

Esteban Fernandez
Esteban Fernandez am 9 Sep. 2015
Some comments?? Thank you very much
dpb
dpb am 9 Sep. 2015
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 am 9 Sep. 2015
Bearbeitet: Walter Roberson am 9 Sep. 2015
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 am 10 Sep. 2015
Is it posible with vectorization? there are many bucles.
Thank you very much
Esteban Fernandez
Esteban Fernandez am 10 Sep. 2015
Someone know how can i start with correct logic? thank you very much
Stephen23
Stephen23 am 10 Sep. 2015
Bearbeitet: Stephen23 am 10 Sep. 2015
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 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

Thorsten
Thorsten am 10 Sep. 2015

1 Stimme

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))

Weitere Antworten (0)

Kategorien

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