<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>eselocoss's Feed - Programmer's Heaven</title>
    <link>http://www.programmersheaven.com/feed/User/333833/RSS.aspx</link>
    <description>Events at Programmer's Heaven related to the user eselocoss.</description>
    <language>en</language>
    <copyright>Copyright 2012 Programmers Heaven</copyright>
    <pubDate>Thu, 09 Feb 2012 06:47:51 -0800</pubDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <item>
      <title>Need help with putting sequence into array</title>
      <link>http://www.programmersheaven.com/mb/java/389880/389880/ReadMessage.aspx#389880</link>
      <description>&lt;p&gt;Posted a '&lt;a href="http://www.programmersheaven.com/mb/java/389880/389880/ReadMessage.aspx#389880"&gt;new message&lt;/a&gt; on the &lt;a href="http://www.programmersheaven.com/mb/java/Board.aspx"&gt;Java&lt;/a&gt; forum.&lt;/p&gt;Ok so basically what I have to do is take an user input sequence of numbers and put them into an array. The only promt the user gets is to input a sequence of numbers... for example:&lt;br /&gt;
&lt;br /&gt;
Input a sequence of numbers: &lt;br /&gt;
    the user inputs 3 5 2 1 7 all in that one line with the numbers seperated by spaces.  the user should be able to input any amount of numbers.&lt;br /&gt;
&lt;br /&gt;
Is there a way to do this without defining the size of the array right away or by taking the length of the sequence the user inputs to define the size of the array?&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/java/389880/389880/ReadMessage.aspx#389880</guid>
      <pubDate>Sun, 26 Apr 2009 14:56:21 -0800</pubDate>
    </item>
    <item>
      <title>Help with find euclid distance with set of data points</title>
      <link>http://www.programmersheaven.com/mb/ctocplusplustomatlab/389870/389870/ReadMessage.aspx#389870</link>
      <description>&lt;p&gt;Posted a '&lt;a href="http://www.programmersheaven.com/mb/ctocplusplustomatlab/389870/389870/ReadMessage.aspx#389870"&gt;new message&lt;/a&gt; on the &lt;a href="http://www.programmersheaven.com/mb/ctocplusplustomatlab/Board.aspx"&gt;Matlab&lt;/a&gt; forum.&lt;/p&gt;So I have to write a function that will find the euclidean distance between every pair of points, given a set of data points X.  Can anyone help me with this.  I am not very good with Matlab.&lt;br /&gt;
&lt;br /&gt;
function [DM] = distance_matrix (X)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Assume that data points in X are represented by the rows of that matrix (there is no class label or&lt;br /&gt;
target value in the last column). &lt;br /&gt;
&lt;br /&gt;
Note that you can build this function from code knn.m (attached here)  with&lt;br /&gt;
minor modifications. Example output you can use to test your code:&lt;br /&gt;
&lt;br /&gt;
X = [1 2 3 4; 5 6 7 8; 9 10 11 12];&lt;br /&gt;
distance_matrix(X)&lt;br /&gt;
&lt;br /&gt;
ans =  0 8 16&lt;br /&gt;
       8 0 8&lt;br /&gt;
      16 8 0&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/ctocplusplustomatlab/389870/389870/ReadMessage.aspx#389870</guid>
      <pubDate>Sun, 26 Apr 2009 11:34:35 -0800</pubDate>
    </item>
    <item>
      <title>Re: Euclidean distance and then find two closest points</title>
      <link>http://www.programmersheaven.com/mb/ctocplusplustomatlab/385793/386033/ReadMessage.aspx#386033</link>
      <description>&lt;p&gt;Posted a '&lt;a href="http://www.programmersheaven.com/mb/ctocplusplustomatlab/385793/386033/ReadMessage.aspx#386033"&gt;reply&lt;/a&gt; on the &lt;a href="http://www.programmersheaven.com/mb/ctocplusplustomatlab/Board.aspx"&gt;Matlab&lt;/a&gt; forum.&lt;/p&gt;How about if instead, I make a function that contains the euclidean_distance code so that it  goes over all of the compenents of x and y (x and y being vectors).&lt;br /&gt;
&lt;br /&gt;
So if I take your code and modify it a little, it might look like the code section below?&lt;br /&gt;
&lt;br /&gt;
I'm just not sure what to do with this part.  &lt;br /&gt;
What would I put in place of the "?" and are the x and y in this equation below in the correct places?&lt;br /&gt;
&lt;br /&gt;
The answer for the output should be this if you run it with the x and y given in the code:  7.3485    2.4495    2.2361&lt;br /&gt;
&lt;br /&gt;
d = 0;&lt;br /&gt;
for i = 1 : size(x, 2) - 1&lt;br /&gt;
    d(i) = d(i) + (x(1, i) - y(?, i)) ^ 2;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;

function d = euclidean_distance (x, y)

%  This wouldn't be in the actual code
% Only here for testing purposes to test the equation below 
x = [1 2 3; 4 5 6; 7 8 9]
y = [ 8 3 4; 5 4 6; 5 6 7]


d = 0;
for i = 1 : size(x, 2) - 1
    d(i) = d(i) + (x(1, i) - y(10, i)) ^ 2;
    
end
d = sqrt(d)


return
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After this is executed, I will have another file that will find the two nearest points. So I believe I need two for loops so it goes over all of the data points and then compares it to all of the other data points.  Also I would call the euclidean_distance function from above inside these loops somehow so that the equation is finding the nearest points of the output form the euclidean_distance function.&lt;br /&gt;
Is this clear... sorry if I'm not good at explaining.&lt;br /&gt;
&lt;br /&gt;
This code might start of like the code below but has to call the euclidean function from above some how.&lt;br /&gt;
This code is of course only for finding the minimum of one vector so another for loop will have to be put in which would also call the euclidean function I believe&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;

D = get_iris()


n = size(a);   % variable "a" being a single vector
min = 0;

for i = 1 : 1 : n
    if a(i) &amp;lt; m
        m = a(i);
    end
end
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here is the working code for "get_iris"&lt;br /&gt;
The iris.data file should be in the attachment for the original post&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
function D = get_iris ()

fid = fopen('iris.data', 'rt');
if (fid == -1)
    error(['The file cannoot be opened!']);
end

i = 1;
while feof(fid) == 0
    %grab line from file
    line = fgetl(fid);
    
    % find all commas
    q = find(line == ',');
    
    % extract numbers
    d = [];
    d(1) = str2num(line(1 : q(1) - 1)); % separately do first element
    
    % now handle all middle elements
    for j = 2 :length(q)
        d(j) = str2num(line(q(j - 1) + 1 : q(j) - 1));
    end

    % now handle the last element
    x = line(q(length(q)) + 1 : length(line));
    
    %strrep(x,'Iris-setosa','0')
    %strrep(x,'Iris-versicolor','1')
    %strrep(x,'Iris-virginica','2')
    
    switch x
        case 'Iris-setosa'
            d(length(d) + 1) = 0
        case 'Iris-versicolor'
            d(length(d) + 1) = 1
        case 'Iris-virginica'
            d(length(d) + 1) = 2
    end
    
    %d(length(d) + 1) = str2num(x);
    
    % put vector into matrix
    D(i, :) = d;
    
    % increment matrix size
    i = i + 1;
   
end
fclose(fid);


return
&lt;/pre&gt;&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/ctocplusplustomatlab/385793/386033/ReadMessage.aspx#386033</guid>
      <pubDate>Fri, 20 Feb 2009 09:10:39 -0800</pubDate>
    </item>
    <item>
      <title>Find two closest points?</title>
      <link>http://www.programmersheaven.com/mb/ctocplusplustomatlab/385793/385991/ReadMessage.aspx#385991</link>
      <description>&lt;p&gt;Posted a '&lt;a href="http://www.programmersheaven.com/mb/ctocplusplustomatlab/385793/385991/ReadMessage.aspx#385991"&gt;reply&lt;/a&gt; on the &lt;a href="http://www.programmersheaven.com/mb/ctocplusplustomatlab/Board.aspx"&gt;Matlab&lt;/a&gt; forum.&lt;/p&gt;How would I go about finding the euclidean distance between all of the points in the data set?  After doing that and having the data points for the euclidean distance, how would I find the two closest points in that set?&lt;br /&gt;
&lt;br /&gt;
Any suggestions will help.  Thanks a lot!&lt;br /&gt;
&lt;br /&gt;
There is an example of the euclidean distance equation in the code.&lt;br /&gt;
I don't think it works correctly though. Also, what would the vectors be? 1 to 150?&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
fid = fopen('iris.data', 'rt');
if (fid == -1)
    error(['The file cannoot be opened!']);
end

i = 1;
while feof(fid) == 0
    %grab line from file
    line = fgetl(fid);
    
    % find all commas
    q = find(line == ',');
    
    % extract numbers
    d = [];
    d(1) = str2num(line(1 : q(1) - 1)); % separately do first element
    
    % now handle all middle elements
    for j = 2 :length(q)
        d(j) = str2num(line(q(j - 1) + 1 : q(j) - 1));
    end

    % now handle the last element
    x = line(q(length(q)) + 1 : length(line));
    
    %strrep(x,'Iris-setosa','0')
    %strrep(x,'Iris-versicolor','1')
    %strrep(x,'Iris-virginica','2')
    
    switch x
        case 'Iris-setosa'
            d(length(d) + 1) = 0
        case 'Iris-versicolor'
            d(length(d) + 1) = 1
        case 'Iris-virginica'
            d(length(d) + 1) = 2
    end
    
    %d(length(d) + 1) = str2num(x);
    
    % put vector into matrix
    D(i, :) = d;
    
    % increment matrix size
    i = i + 1;
   
end
fclose(fid);


%%
% calculate Euclidean distance between vectors 1 and 10
% this was an example of an equation I found...
d = 0;
for i = 1 : size(D, 2) - 1
    d = d + (D(1, i) - D(10, i)) ^ 2;
end
d = sqrt(d)
&lt;/pre&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/ctocplusplustomatlab/385793/385991/ReadMessage.aspx#385991</guid>
      <pubDate>Thu, 19 Feb 2009 12:06:26 -0800</pubDate>
    </item>
    <item>
      <title>Re: Need help with this code please</title>
      <link>http://www.programmersheaven.com/mb/ctocplusplustomatlab/385793/385927/ReadMessage.aspx#385927</link>
      <description>&lt;p&gt;Posted a '&lt;a href="http://www.programmersheaven.com/mb/ctocplusplustomatlab/385793/385927/ReadMessage.aspx#385927"&gt;reply&lt;/a&gt; on the &lt;a href="http://www.programmersheaven.com/mb/ctocplusplustomatlab/Board.aspx"&gt;Matlab&lt;/a&gt; forum.&lt;/p&gt;Yes, that did work! Thank you very much for all of the help!&lt;br /&gt;
I appreciate it very much!&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/ctocplusplustomatlab/385793/385927/ReadMessage.aspx#385927</guid>
      <pubDate>Wed, 18 Feb 2009 10:19:06 -0800</pubDate>
    </item>
    <item>
      <title>Re: Need help with this code please</title>
      <link>http://www.programmersheaven.com/mb/ctocplusplustomatlab/385793/385923/ReadMessage.aspx#385923</link>
      <description>&lt;p&gt;Posted a '&lt;a href="http://www.programmersheaven.com/mb/ctocplusplustomatlab/385793/385923/ReadMessage.aspx#385923"&gt;reply&lt;/a&gt; on the &lt;a href="http://www.programmersheaven.com/mb/ctocplusplustomatlab/Board.aspx"&gt;Matlab&lt;/a&gt; forum.&lt;/p&gt;These lines are supposed to change the string such as "Iris-setosa" to the string "0" and same for the others except with the different numbers.&lt;br /&gt;
&lt;br /&gt;
strrep(x,'Iris-setosa','0')&lt;br /&gt;
strrep(x,'Iris-versicolor','1')&lt;br /&gt;
strrep(x,'Iris-virginica','2')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So if you open up the data set as text, All the iris-setosa, iris-versicolor, and iris-virginica should be changed to the respected string of a number that is listed above.  &lt;br /&gt;
&lt;br /&gt;
That is why I use the str2num function because I want to change the "0", "1", and "2" strings to the actual number to put in the matrix.&lt;br /&gt;
&lt;br /&gt;
Yes, x should change from 'iris-setosa' to '0' and so on and so forth for the others.&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/ctocplusplustomatlab/385793/385923/ReadMessage.aspx#385923</guid>
      <pubDate>Wed, 18 Feb 2009 09:38:43 -0800</pubDate>
    </item>
    <item>
      <title>Re: Need help with this code please</title>
      <link>http://www.programmersheaven.com/mb/ctocplusplustomatlab/385793/385920/ReadMessage.aspx#385920</link>
      <description>&lt;p&gt;Posted a '&lt;a href="http://www.programmersheaven.com/mb/ctocplusplustomatlab/385793/385920/ReadMessage.aspx#385920"&gt;reply&lt;/a&gt; on the &lt;a href="http://www.programmersheaven.com/mb/ctocplusplustomatlab/Board.aspx"&gt;Matlab&lt;/a&gt; forum.&lt;/p&gt;here is the updated code that should work better.  I don't understand what I have to change to get this error to work.&lt;br /&gt;
&lt;br /&gt;
The error I am getting is...&lt;br /&gt;
"""&lt;br /&gt;
???  In an assignment  A(I) = B, the number of elements in B and&lt;br /&gt;
 I must be the same.&lt;br /&gt;
&lt;br /&gt;
Error in ==&amp;gt; get_iris2 at 31&lt;br /&gt;
    d(length(d) + 1) = str2num(x);&lt;br /&gt;
"""&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
fid = fopen('iris.data', 'rt');
if (fid == -1)
    error(['The file cannoot be opened!']);
end

i = 1;
while feof(fid) == 0
    %grab line from file
    line = fgetl(fid);
    
    % find all commas
    q = find(line == ',');
    
    % extract numbers
    d = [];
    d(1) = str2num(line(1 : q(1) - 1)); % separately do first element
    
    % now handle all middle elements
    for j = 2 :length(q)
        d(j) = str2num(line(q(j - 1) + 1 : q(j) - 1));
    end

    % now handle the last element
    x = line(q(length(q)) + 1 : length(line));
    
    strrep(x,'Iris-setosa','0')
    strrep(x,'Iris-versicolor','1')
    strrep(x,'Iris-virginica','2')
    
    d(length(d) + 1) = str2num(x);
    
    % put vector into matrix
    D(i, :) = d;
    
    % increment matrix size
    i = i + 1;
    
end

fclose(fid);
&lt;/pre&gt;&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/ctocplusplustomatlab/385793/385920/ReadMessage.aspx#385920</guid>
      <pubDate>Wed, 18 Feb 2009 08:52:56 -0800</pubDate>
    </item>
    <item>
      <title>Need help with this code please</title>
      <link>http://www.programmersheaven.com/mb/ctocplusplustomatlab/385793/385793/ReadMessage.aspx#385793</link>
      <description>&lt;p&gt;Posted a '&lt;a href="http://www.programmersheaven.com/mb/ctocplusplustomatlab/385793/385793/ReadMessage.aspx#385793"&gt;new message&lt;/a&gt; on the &lt;a href="http://www.programmersheaven.com/mb/ctocplusplustomatlab/Board.aspx"&gt;Matlab&lt;/a&gt; forum.&lt;/p&gt;I just started using MATLAB and I need help with some code that I am trying to execute.  What I have to do is take the iris.data file which is in the attachment, and read the data into a matrix.  The last line is a string which gives a name of a flower and depending on what name, it has to be changed to 0, 1, or 2 and update the matrix.  Here is the code that I have right now but I am getting an error for line 16 that says "Index exceeds matrix dimensions."   &lt;br /&gt;
&lt;br /&gt;
If you can please help me to get this to work that would be great.  thanks a lot.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
fid = fopen('iris.data', 'rt');
if (fid == -1)
    error(['The file cannoot be opened!']);
end

i = 1;
while feof(fid) == 0
    %grab line from file
    line = fgetl(fid);
    
    % find all commas
    clcq = find(line == ',');
    
    % extract numbers
    d = [];
    d(1) = str2num(line(1 : q(1) - 1)); % separately do first element
    
    % now handle all middle elements
    for j = 2 :length(q)
        d(j) = str2num(line(q(j - 1) + 1 : q(j) - 1));
    end

    x = line(q(length(q)) + 1 : length(line));
    
    strrep(x,'Iris-setosa','0')
    strrep(x,'Iris-versicolor','1')
    strrep(x,'Iris-virginica','2')

    % now handle the last element
    d(length(d) + 1) = str2num(x);
    
    % put vector into matrix
    D(i, :) = d;
    
    % increment matrix size
    i = i + 1;
    
end

fclose(fid);

&lt;/pre&gt;&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/ctocplusplustomatlab/385793/385793/ReadMessage.aspx#385793</guid>
      <pubDate>Mon, 16 Feb 2009 14:07:57 -0800</pubDate>
    </item>
  </channel>
</rss>
