-
March 19th, 2014, 12:29 PM
#1
[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 :
and the result must be :
Any suggestion? Thanks anyway
-
March 19th, 2014, 05:31 PM
#2
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.
-
March 19th, 2014, 06:13 PM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|