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 Exchange에서 Get 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