[RESOLVED] Classification
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: [RESOLVED] Classification

  1. #1
    Join Date
    Mar 2014
    Posts
    2

    [RESOLVED] Classification

    Hello there!
    I am trying to make a programm that classifies data , but i don't get the right result.

    Here is my code :
    Code:
    Open "C:\Temp\data1.txt" For Input As #3
    Open "C:\Temp\data2.txt" For Output As #4
    Dim R(4) As Double
    
    Do While Not EOF(3)
    Input #3, R(1), R(2), R(3), R(4)
    
    For k = 1 To 4
    If R(k) >= 0 And R(i) <= 10 Then
    R(k) = 1
    ElseIf R(k) >= 11 And R(k) <= 20 Then
    R(k) = 2
    ElseIf R(k) >= 21 And R(k) <= 30 Then
    R(k) = 3
    ElseIf R(k) >= 31 And R(k) <= 40 Then
    R(k) = 4
    ElseIf R(k) >= 41 And R(k) <= 50 Then
    R(k) = 5
    End If
    
    Next k
    Print #4, R(1), R(2), R(3), R(4)
    Loop
    
    Close #4
    Close #3
    For example i have d1 txt file :
    27 32 44 49
    4 12 38 22

    and the result must be :
    3 4 5 5
    1 2 4 3

    Any suggestion? Thanks anyway

  2. #2
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,825

    Re: Classification

    So what results are you getting?

    At a glance the code looks like it should work assuming the file is comma delimited or each value is on a different line.
    If the file looks like your sample then that would not work.

    You also do not need so much code for example the second line of your If statement test if >=11 and <=20 but the code will not get there if it is not either <0 or >10
    This could easier to read and likely faster using a select case
    Code:
    Select Case R(k)
       Case <0
       Case <11
           R(K)=1
       Case <21
       Case <31
       Case <41
       Case <51
    End Select
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Mar 2014
    Posts
    2

    Re: Classification

    Thank you very much!! Now it works great with case statement!
    My previous code works fine only for the first line , not for the second,third etc...
    Thanks once again!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center