0
votes

First time here so please be gentle

So the basic idea is i have folders with just txt files that has about 20000 points each. I only want specific intervals from each of them.

I have a made a single file with the ranges for that looks like this . 2715 2955 1132 1372

each row representing the range i want in one file

I want to batch load all the files and export the just the ranges of each. Ive lost too much sleep over this please help

    dirName = '*';              %# folder path
 files = dir( fullfile(dirName,'*.txt') );   %# list all *.xyz files
  files = {files.name}' ;                     %'# file names
 data = cell(numel(files),1)  ;              %# store file contents
 for u=1:numel(files)
   A=files{u}  ;   %# full path to file
 files{u};

   STR1 = A

  B=load(STR1);
  end

This is all i have come up with in 2 days. im new to matlab Thanks

1
Please describe what's wrong with your code. What is dirName = '*'; supposed to do? - Daniel
so thats where i load the directory i have all the separate text files. it would look something like C:\Users\work. edit sorry where i set path - display
the problem is its not loading all the files. I think if i managed to get the files in the i can use newfilename[range(1,1):range(2,1)] then export that - display

1 Answers

0
votes

A very good help is the matlab help of fscanf, http://www.mathworks.co.uk/help/matlab/ref/fscanf.html. Also, in your load you don't have the path. Replace the last two lines in your for loop with:

STR1 = [dirName A]
fileID = fopen(STR1,'r');
formatSpec = '%f';
B = fscanf(fileID,formatSpec)

Or try:

delim = ' '; 
nrhdr = 0; 
STR1 = [dirName A]
A = importdata(STR1, delim, nrhdr); 

A.data will be your data, I'm assuming no header lines.