如何从file.txt的获取数组,我需要? (在X-code) [英] how to get from a file.txt the array that i need? ( in X-code)
问题描述
我不知道,如果它的可能。
在我的应用我现在的储蓄在file.txt的阵列的列表。 (例如:
i don't know if its possible. in my app i am saving a list of arrays in a file.txt. ( e.g. :
16 2012-08-30: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
16 2012-08-30: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
16 2012-08-30: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
...
和我需要(第一个数字数组):-0.818863
and i need ( the first numbers array): -0.818863
-1.024597
0.754196
例如在gnuplot的是更多钞票
e.g in Gnuplot it is posible
plot "file.txt"using 2:7
我需要这个数组通过FFT对其进行过滤,这是我的code:
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 );
这可能吗?怎么样?
is it possible ? how?
推荐答案
如果格式始终是相同的,那么你可以拆分在这种情况下,已知的分隔符字符串中,你可以得到使用类似数据的列:
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的获取数组,我需要? (在X-code)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!