如何从file.txt获取我需要的数组? (在Xcode中) [英] How to get from a file.txt the array that I need? (in Xcode)

查看:63
本文介绍了如何从file.txt获取我需要的数组? (在Xcode中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道是否可能。
在我的应用程序中,我将数组列表保存在file.txt中。 (例如:

I don't know if it's possible. In my app I am saving a list of arrays in a file.txt. (e.g.:


2012-09-02 16:27:15.010 SMAccelerometerDataLogger [1950:707] -0.818863 0.286575 0.206177

2012-09-02 16:27:15.010 SMAccelerometerDataLogger[1950:707] -0.818863 0.286575 0.206177

2012-09-02 16:27:15.017 SMAccelerometerDataLogger [1950:707] -1.024597 0.380875 0.456131

2012-09-02 16:27:15.017 SMAccelerometerDataLogger[1950:707] -1.024597 0.380875 0.456131

2012-09-02 16:27:15.023 SMAccelerometerDataLogger [1950:707] -0.754196 0.417053 1.165237

2012-09-02 16:27:15.023 SMAccelerometerDataLogger[1950:707] -0.754196 0.417053 1.165237

...

,我需要(第一个数字数组):

and I need (the first numbers array):

     -0.818863

     -1.024597

     0.754196

例如在Gnuplot中是可能的

e.g in Gnuplot it is possible

plot "file.txt"using 2:7

$ b绘制 file.txt
$ b

我需要此数组通过FFT对其进行过滤,这是我的代码:

I need this array to filter it by FFT, here is my code:

int SIZE = 97;

fftw_complex    *data, *fft_result, *ifft_result;
fftw_plan       plan_forward, plan_backward;
int             i;

data        = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * SIZE);
fft_result  = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * SIZE);
ifft_result = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * SIZE);

plan_forward  = fftw_plan_dft_1d(SIZE, data, fft_result,
                                 FFTW_FORWARD, FFTW_ESTIMATE);
plan_backward = fftw_plan_dft_1d(SIZE, fft_result, ifft_result,
                                 FFTW_BACKWARD, FFTW_ESTIMATE);


for( i = 0 ; i < SIZE ; i++ ) {
    data[i][0] = array[i][0];//>>>> here i should use the array that i need

    data[i][1] = 0.0; 
}


for( i = 0 ; i < SIZE ; i++ ) {
    fprintf( stdout, "data[%d] = { %2.2f, %2.2f }\n",
            i, data[i][0], data[i][1] );
}

fftw_execute( plan_forward );


for( i = 0 ; i < SIZE ; i++ ) {
    fprintf( stdout, "fft_result[%d] = { %2.2f, %2.2f }\n",
            i, fft_result[i][0], fft_result[i][1] );
}

fftw_execute( plan_backward );


for( i = 0 ; i < SIZE ; i++ ) {
    fprintf( stdout, "ifft_result[%d] = { %2.2f, %2.2f }\n",
            i, ifft_result[i][0] / SIZE, ifft_result[i][1] / SIZE );
}


fftw_destroy_plan( plan_forward );
fftw_destroy_plan( plan_backward );

fftw_free( data );
fftw_free( fft_result );
fftw_free( ifft_result );

有可能吗?怎么样?

推荐答案

如果格式始终相同,则可以用已知的分隔符分割字符串,在这种情况下,可以获取该列使用类似以下内容的数据:

If the format is always the same then you could split the string by the known delimiter in this case you could get that column of data using something like:

NSArray *components = [line componentsSeparatedByString:@" "];
if (components.count > 3) {
  NSLog(@"%@", components[3]);
}

这篇关于如何从file.txt获取我需要的数组? (在Xcode中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆