From: Matt Fetterman on
"Frank Sabouri" <Frank.Sabouri(a)gmail.com> wrote in message <hho71f$t33$1(a)fred.mathworks.com>...
> "Matt Fetterman" <mattinjersey(a)yahoo.com> wrote in message <hhmp1i$bc2$1(a)fred.mathworks.com>...
> > "Frank Sabouri" <Frank.Sabouri(a)gmail.com> wrote in message <hhmnvu$7a4$1(a)fred.mathworks.com>...
> > > "Matt Fetterman" <mattinjersey(a)yahoo.com> wrote in message <hhmkfd$t5s$1(a)fred.mathworks.com>...
> > > > "Frank Sabouri" <Frank.Sabouri(a)gmail.com> wrote in message <hhmifj$q68$1(a)fred.mathworks.com>...
> > > > > 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
> > > > >
> > > > >
> > > >
> > > > Perhaps you could explain what the error is that you are getting or how it is going wrong?
> > > > Regards Matt
> > >
> > > 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
> >
> > 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
>
> 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

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
From: Frank Sabouri on
"Matt Fetterman" <mattinjersey(a)yahoo.com> wrote in message <hho7o0$d1i$1(a)fred.mathworks.com>...
> "Frank Sabouri" <Frank.Sabouri(a)gmail.com> wrote in message <hho71f$t33$1(a)fred.mathworks.com>...
> > "Matt Fetterman" <mattinjersey(a)yahoo.com> wrote in message <hhmp1i$bc2$1(a)fred.mathworks.com>...
> > > "Frank Sabouri" <Frank.Sabouri(a)gmail.com> wrote in message <hhmnvu$7a4$1(a)fred.mathworks.com>...
> > > > "Matt Fetterman" <mattinjersey(a)yahoo.com> wrote in message <hhmkfd$t5s$1(a)fred.mathworks.com>...
> > > > > "Frank Sabouri" <Frank.Sabouri(a)gmail.com> wrote in message <hhmifj$q68$1(a)fred.mathworks.com>...
> > > > > > 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
> > > > > >
> > > > > >
> > > > >
> > > > > Perhaps you could explain what the error is that you are getting or how it is going wrong?
> > > > > Regards Matt
> > > >
> > > > 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
> > >
> > > 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
> >
> > 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
>
> 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
Hi Matt,

Now, it works.

Thanks,
Frank
First  |  Prev  | 
Pages: 1 2
Prev: smes unit
Next: Slow/Fast Rayleigh Fading