From: eesa on
I have the following code but the result it returns to me in one colum but what i need iis that when the value of the loop change, i want to give me the result in different cloum
defined x is a metrix

for i=1:18,
for j=i+1:19,
d=x(:,i);
y=x(:,j);
p=[d y];
f=kmeans(p,14)
end
end

Now, the above code return to me the all of the result in one colum and i want to get the result into different colums.

Thanks in Adance
From: eesa on
"eesa " <alalyani(a)hotmail.com> wrote in message <i402ca$9ud$1(a)fred.mathworks.com>...
> I have the following code but the result it returns to me in one colum but what i need iis that when the value of the loop change, i want to give me the result in different cloum
> defined x is a metrix
>
> for i=1:18,
> for j=i+1:19,
> d=x(:,i);
> y=x(:,j);
> p=[d y];
> f=kmeans(p,14)
> end
> end
>
> Now, the above code return to me the all of the result in one colum and i want to get the result into different colums.
>
> Thanks in Adance
please help me on that i tried several ways but it does not work.
From: Steven_Lord on


"eesa " <alalyani(a)hotmail.com> wrote in message
news:i402ca$9ud$1(a)fred.mathworks.com...
> I have the following code but the result it returns to me in one colum but
> what i need iis that when the value of the loop change, i want to give me
> the result in different cloum
> defined x is a metrix
>
> for i=1:18,
> for j=i+1:19,
> d=x(:,i);
> y=x(:,j);
> p=[d y];
> f=kmeans(p,14)
> end end
>
> Now, the above code return to me the all of the result in one colum and i
> want to get the result into different colums.

Every iteration through the loop, you're overwriting d, y, p, and f.
Instead of overwriting, preallocate them to be the correct size BEFORE the
loop and fill them in using indexed assignment inside the loop. As a
simpler example you can adapt to your program:

x = zeros(10, 1);
for k = 1:10
x(k, :) = k.^2;
end

[And yes, I know there's a simpler way to do that. I'm using it simply to
demonstrate the techniques of preallocation and indexed assignment.]

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com