From: xiong on
Hello for everyone,
I am beginning in Matlab.
This is a vector:
[1 1 1 1 1 1 1 1 1 2 2 3 4 3 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 3 2 2 3 4 3 2 3 2 1 1 1 1 1]
I choose those values over "2":
[0 0 0 0 0 0 0 0 0 0 0 3 4 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 0 3 4 3 0 3 0 0 0 0 0 0]
I have 4 clusters.I search for the maximum value of each cluster:
[0 0 0 0 0 0 0 0 0 0 0 0 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 0 0 4 0 0 3 0 0 0 0 0 0]
I have 4 local maxima(4,3,4and3).The last three are very close to each other(the discrepancy of the index <5).Therefore, I take only the highest one:
[0 0 0 0 0 0 0 0 0 0 0 0 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 0 0 0 0 0 0 0 0 0].
My questiion is: How to achieve it in Matlab code?

Thanks.
From: Rune Allnor on
On 21 Jan, 13:27, "xiong " <xionglei092...(a)sina.com> wrote:
> Hello for everyone,
> I am beginning in Matlab.
....
> My questiion is: How to achieve it in Matlab code?

If this is easy, and you are a beginner, why should anyone
help you? You might learn more matlab faster if you do
the excercises yourself. In fact, homework is a basic
foundation of courses, and has been, for a very long time.

Rune
From: xiong on
Rune Allnor <allnor(a)tele.ntnu.no> wrote in message <04ea5882-d81d-40bb-a911-16808908afca(a)y23g2000yqm.googlegroups.com>...
> On 21 Jan, 13:27, "xiong " <xionglei092...(a)sina.com> wrote:
> > Hello for everyone,
> > I am beginning in Matlab.
> ...
> > My questiion is: How to achieve it in Matlab code?
>
> If this is easy, and you are a beginner, why should anyone
> help you? You might learn more matlab faster if you do
> the excercises yourself. In fact, homework is a basic
> foundation of courses, and has been, for a very long time.
>
> Rune
Thank you for your advice.Actually,It is not easy for me.Would you like to give me some prompt ?
From: ImageAnalyst on
You didn't say what to do if there were a local max (like with a value
of 3) that was NOT within a certain distance of your "4" cluster. Do
you keep the one with value 3 in that case, or throw it out because it
doesn't have the max value of 4? That gets a little complicated (but
not very hard at all if you have the Image Processing Toolbox - just
compare distances between centroids and throw out clusters that are
too close to a bigger cluster). Otherwise to simply find what you
gave as your desired, final output:

a = [1 1 1 1 1 1 1 1 1 2 2 3 4 3 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 3
2 2 3 4 3 2 3 2 1 1 1 1 1]
maxIndexes = find(a == max(a))
b = zeros(1, length(a));
b(maxIndexes) = a(maxIndexes)
From: Matthew on
We won't tell you explicitly how to do your homework (at least not without some demonstrated effort), but here's a hint: the functions 'find' and 'diff' should be useful to you.

help find
help diff

"xiong " <xionglei092292(a)sina.com> wrote in message <hj9la0$2dm$1(a)fred.mathworks.com>...
> Rune Allnor <allnor(a)tele.ntnu.no> wrote in message <04ea5882-d81d-40bb-a911-16808908afca(a)y23g2000yqm.googlegroups.com>...
> > On 21 Jan, 13:27, "xiong " <xionglei092...(a)sina.com> wrote:
> > > Hello for everyone,
> > > I am beginning in Matlab.
> > ...
> > > My questiion is: How to achieve it in Matlab code?
> >
> > If this is easy, and you are a beginner, why should anyone
> > help you? You might learn more matlab faster if you do
> > the excercises yourself. In fact, homework is a basic
> > foundation of courses, and has been, for a very long time.
> >
> > Rune
> Thank you for your advice.Actually,It is not easy for me.Would you like to give me some prompt ?