Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

PDIST

1 view
Skip to first unread message

Frank Sabouri

unread,
Jan 1, 2010, 11:36:04 PM1/1/10
to
Hi:

There is a matrix that is "x" [different conditions (168)-by-variables (9)]. You suppose that I made 28 different sub-matrices from "x", wherein size of each sub-matrix is (6-by-9). I want to compute Euclidean distances among 9 variables for any given sub-matrix.

X (:,:,:)=subdivide (x,6,9); % size of cell is (6,9,28)
for i = 1:28,
[Y] = pdist (X(:,:,i)');
Ym=mean (Y) ;
Z=linkage(Ym,'average');
end

May please somebody show me where the problem is.

Thanks,

Frank


Matt Fetterman

unread,
Jan 2, 2010, 12:10:05 AM1/2/10
to
"Frank Sabouri" <Frank....@gmail.com> wrote in message <hhmifj$q68$1...@fred.mathworks.com>...

Perhaps you could explain what the error is that you are getting or how it is going wrong?
Regards Matt

Frank Sabouri

unread,
Jan 2, 2010, 1:10:06 AM1/2/10
to
"Matt Fetterman" <mattin...@yahoo.com> wrote in message <hhmkfd$t5s$1...@fred.mathworks.com>...

Hi Matt:

Actually, I expected to get an output (Y) that is a matrix (28-by-36) that depicts Euclidean distances for 28 different sub-matrices; however, the output is only a vector that shows Euclidean distances for only one of sub-matrices which is number 28.

Cheers,

Frank

Matt Fetterman

unread,
Jan 2, 2010, 1:28:02 AM1/2/10
to
"Frank Sabouri" <Frank....@gmail.com> wrote in message <hhmnvu$7a4$1...@fred.mathworks.com>...

Hi Frank, The problem is with your loop. The loop cycles through different values of i and you will want to assign the output of each time you run the loop to a different variable or a different spot in the output matrix. For example,
P(i,1:10)=Z;

Regards! Matt

Frank Sabouri

unread,
Jan 2, 2010, 2:33:03 PM1/2/10
to
"Matt Fetterman" <mattin...@yahoo.com> wrote in message <hhmp1i$bc2$1...@fred.mathworks.com>...

Hi Matt,

I tried to insert your comment on the loop. Please let me know if it is what I should do.

for i = 1:28,
[Y] = pdist (X(:,:,i)');

P(i,1:28)=28;
end

Ym=mean (Y) ;
Z=linkage(Ym,'average');

Regadrs,
Farnk

Matt Fetterman

unread,
Jan 2, 2010, 2:45:04 PM1/2/10
to
"Frank Sabouri" <Frank....@gmail.com> wrote in message <hho71f$t33$1...@fred.mathworks.com>...

Hi Frank,
No that is not quite what I meant.
Look at your original loop:

for i = 1:28,
[Y] = pdist (X(:,:,i)');
Ym=mean (Y) ;
Z=linkage(Ym,'average');
end

This loop executes 28 times and produces a different value of Z every time.
So in your original program, the output value of Z will be that value obtained for the last value of the loop, when i=28. But what you want is to store the value of Z for every value of the loop, from i=1 to 28.
I am not sure of the size of Z in your program. Maybe it is 1x9 ?
So the modified loop could look like this :

for i = 1:28,
[Y] = pdist (X(:,:,i)');
Ym=mean (Y) ;
Z=linkage(Ym,'average');

Zout(i,1:9)=Z;
end;

And you see what that does, it stores the value of Z in a different location for each value of i. Then the Zout variable will contain your desired data.

Regards! Matt

Frank Sabouri

unread,
Jan 3, 2010, 12:13:03 AM1/3/10
to
"Matt Fetterman" <mattin...@yahoo.com> wrote in message <hho7o0$d1i$1...@fred.mathworks.com>...
Hi Matt,

Now, it works.

Thanks,
Frank

0 new messages