1

I have a comma delimited single text file with strings and integers that I'm trying to import into a cell array. I then want to export it to several files based on the same Resonance Freq. and add text to the filename row

This is a sample of the text file to import: (please note the file will be much larger then this)

Resonance Freq,number,Filename,time,fs,Split-3675,Session Num
277.912902832031250,1,p000001,00:00:01,44100,3675,0
123.912902832031250,2,p000002,00:00:02,44100,3675,2
277.912902832031250,3,p000003,00:00:03,44100,3675,0
277.912902832031250,4,p000001,00:00:01,44100,3675,1
343.912902832031250,5,p000002,00:00:02,44100,3675,0
277.912902832031250,6,p000003,00:00:03,44100,3675,4

And this is the exported text files I want created (text file1)

277.912902832031250,1,/tmp/p000001.wav,00:00:01,44100,3675,0
277.912902832031250,3,/tmp/p000003.wav,00:00:03,44100,3675,0
277.912902832031250,4,/tmp/p000001.wav,00:00:01,44100,3675,1

And this is the exported text files I want created (text file2)

123.912902832031250,2,/tmp/p000002.wav,00:00:02,44100,3675,2

And this is the exported text files I want created (text file3)

343.912902832031250,5,/tmp/p000002.wavadded ,00:00:02,44100,3675,0

I'm having a problem with fscanf and using comma delimited data

fid = fopen('/tmp/freq_range_color_coded.txt');
m_s = fscanf(fid,'%f %f %s %s %f %f %f');
fclose(fid);

when I access a cell like m_s(1,2) I get back a single letter instead of a field. How can I get it so when I type m_s(1,2) I get back the whole field example

m_s(2,1) should give me 277.912902832031250

thanks

PS I'm using octave and textscan is not compatible with it.

Rick T
  • 3,349
  • 10
  • 54
  • 119
  • "saying it's undefined.". Could you expand on this? – Franck Dernoncourt Mar 27 '13 at 14:49
  • strread and textscan in Octave 3.4.0 are not fully compatible with their implementations in Matlab 2009b (and probably later versions as well). For instance, the N=-1 option (repeat reading format until end of string) is not implemented in Octave 3.4.0 . Using a value of N=a positive integer (read format N times) does work the same as in Matlab. I'll have to use fscanf with delimters – Rick T Mar 27 '13 at 15:05

2 Answers2

2

Try skipping the header line when importing with textscan:

fid = fopen('/tmp/freq_range_color_coded.txt');
m_s = textscan(fid,'%f %f %s %s %f %f %f','delimiter', ',', 'HeaderLines', 1);
fclose(fid);
DMR
  • 1,479
  • 1
  • 8
  • 11
  • this didn't work comes back with error: `textscan' undefined near line 6. which is the textscan code line – Rick T Mar 27 '13 at 14:40
  • it looks like octave textscan is not fully compatible with matlab. strread and textscan in Octave 3.4.0 are not fully compatible with their implementations in Matlab 2009b (and probably later versions as well). For instance, the N=-1 option (repeat reading format until end of string) is not implemented in Octave 3.4.0 . Using a value of N=a positive integer (read format N times) does work the same as in Matlab. I'll have to use fscanf but can it use delimiters – Rick T Mar 27 '13 at 15:04
0

it looks like octave textscan is not fully compatible with matlab. strread and textscan in Octave 3.4.0 are not fully compatible with their implementations in Matlab 2009b (and probably later versions as well). For instance, the N=-1 option (repeat reading format until end of string) is not implemented in Octave 3.4.0 . Using a value of N=a positive integer (read format N times) does work the same as in Matlab. I'll have to use fscanf but can it use delimiters

Rick T
  • 3,349
  • 10
  • 54
  • 119