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.

4

2 回答 2

2

使用 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);
于 2013-03-27T14:36:51.027 回答
0

看起来 octave textscan 与 matlab 不完全兼容。Octave 3.4.0 中的 strread 和 textscan 与它们在 Matlab 2009b 中的实现不完全兼容(可能还有更高版本)。例如,在 Octave 3.4.0 中没有实现 N=-1 选项(重复读取格式直到字符串结束)。使用 N=a 正整数(读取格式 N 次)的值与在 Matlab 中的工作方式相同。我将不得不使用 fscanf 但它可以使用分隔符吗

于 2017-07-07T12:53:52.907 回答