»
 

Go Back   ResellerRatings Store Ratings > ResellerRatings Forums > Tech Support

Reply
 
LinkBack Thread Tools Display Modes
Old 06-24-2003, 02:16 PM   #1 (permalink)
Registered User
 
Join Date: Jul 2002
Location: North Jersey or Southern RI take your pick
Posts: 114
jon112981 is on a distinguished road
Send a message via AIM to jon112981 Send a message via Yahoo to jon112981
help deleting lines

I need some help processing a rather large file I have. The file contains some data in a nice matrix form (40x13 all numbers) and some ugly headerlines with a random assortment of strings and numbers. It follows the pattern 6 lines of header, 40 lines of data about 2100 times. What I am interested in doing is finding some program, in anything, to delete the headerlines and leave the 40 lines of data. It can be a unix script, a dos script or in any language at all. The end result will go into MATLAB. I know next to nothing about UNIX but was looking around at some of the commands, that might be the way to go. If anyone could help start me out on a solution I'd greatly appreciate it.

jon112981 is offline   Reply With Quote
Old 06-24-2003, 02:25 PM   #2 (permalink)
Registered User
 
originel's Avatar
 
Join Date: Jun 2002
Location: Texas Tech
Posts: 1,538
originel is on a distinguished road
Send a message via AIM to originel
hmm...well with something like this i don't know of anything that would do it for you. you could write your own shell script in 'nix to do it (since it can do some c stuff). but personally i would recommend just writing an actual program to do that. it would be pretty easy if you're familiar with programming.
originel is offline   Reply With Quote
Old 06-24-2003, 02:38 PM   #3 (permalink)
Registered User
 
Emc2's Avatar
 
Join Date: Oct 2001
Location: Savannah, GA
Posts: 1,612
Emc2 is on a distinguished road
Send a message via AIM to Emc2
mmmmm.....Matlab.....I love Matlab for lunch....it just requires late late nights of preparation...

Look around in Matlab...I know there's a way to input data from a non-Matlab file into Matlab, but I don't remember how.

Then you could just use for loops to manipulate in a various amount of ways:

head=0;
for n=[0:2100] % 2100=# of instances this pattern occurs
for i=[1:40]; %row i of occurance n of the pattern
for j=[1:13]; %column
newMatrix[i+40*n,j] = oldMatrixFromFile[i+40*n+head*n,j];
end
end
head = head+6; %6 is the number of header lines b/t data
end

I wrote this mini code, just to give an initial idea. I don't think it will directly work. This also assumes that you can get the entire data file into Matlab into matrix form.

Hope this gives you some direction...I'll soon be doing some research in which I'll have to manipulate large amounts of data as well
Emc2 is offline   Reply With Quote
Old 06-24-2003, 02:41 PM   #4 (permalink)
Registered User
 
Join Date: Jul 2002
Location: North Jersey or Southern RI take your pick
Posts: 114
jon112981 is on a distinguished road
Send a message via AIM to jon112981 Send a message via Yahoo to jon112981
I'm not incredibly familiar with programing syntax for any acutal language. I've had theory (lots of it) but we only used MATLAB (I still have to take the basic compsci classes before they let me graduate). MATLAB's main limitaitions comes in that the data file must all be formatted the same for it to read it. So the varying number of columns doens't work at all. Would something like C/C++ or Java be capable of doing this?
jon112981 is offline   Reply With Quote
Old 06-24-2003, 03:06 PM   #5 (permalink)
Registered User
 
Join Date: Jul 2002
Location: North Jersey or Southern RI take your pick
Posts: 114
jon112981 is on a distinguished road
Send a message via AIM to jon112981 Send a message via Yahoo to jon112981
Yeah EMC that's origionally what I wanted to do but loading the matrix is a pain in the @$$ in matlab. Okay the first line has 13 colums, the next line has 9 columns, the third has 3, the 4th has 5 and so on. The 6th has 2 strings in it, then I hit the nice 40 lines and start over again. I know textread won't load this as all rows must have the same number of columns. I totally don't get fscanf, someone here said that should work but I don't understand how or what to do with it.
jon112981 is offline   Reply With Quote
Old 06-24-2003, 05:27 PM   #6 (permalink)
Registered User
 
originel's Avatar
 
Join Date: Jun 2002
Location: Texas Tech
Posts: 1,538
originel is on a distinguished road
Send a message via AIM to originel
yeah, c/c++ and java can do this no problem.

in c++ it would look something kinda like this:
Code:
int c, line = 0;
ifstream infile;
ofstream outfile;
string mystring;
string mydata[<number of lines of data>];
infile.open("<nameoffile>");
while(infile)
{
//this takes care of the 6 lines of header
     for(c = 0;c < 6;c++)
           infile.getline(mystring);
//this takes care of the 40 lines of data
     for(c = 0; c < 40;c++)
     {
           infile.getline(mystring);
           mydata[line] = mystring;
           line++;
     }
}
infile.close();
outfile.open("<output file name>");
for(c = 0; c < number of lines of data; c++)
     outfile.write(mydata[line]);
outfile.close();
note: if there are blank lines separating headers or lines of code and the like you will need to add an extra getline for each. also i used the fstream library (part of the standard library), but you can use whatever you want to use.

EDIT: also i don't think this will work right off, it's been a while since i've used the standard library and i didn't compile this. and i think that getline and write take another parameter, just can't remember what it is

Last edited by originel; 06-24-2003 at 05:36 PM.
originel is offline   Reply With Quote
Old 07-03-2003, 12:45 PM   #7 (permalink)
Registered User
 
Join Date: Jul 2002
Location: North Jersey or Southern RI take your pick
Posts: 114
jon112981 is on a distinguished road
Send a message via AIM to jon112981 Send a message via Yahoo to jon112981
I got it! thanks all you guys for your help. If anyone is looking for a way to do this in matlab there is a command similar to getline(in c++) called fgetl. It reads one line at a time as a string.
jon112981 is offline   Reply With Quote
Reply




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Most Active Discussions

Recent Discussions

All times are GMT -6. The time now is 04:11 AM.