How to get from a file.txt the array that I need? (in Xcode)












0















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.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



...




and I need (the first numbers array):



     -0.818863

-1.024597

0.754196


e.g in Gnuplot it is possible



plot "file.txt"using 2:7


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?










share|improve this question





























    0















    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.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



    ...




    and I need (the first numbers array):



         -0.818863

    -1.024597

    0.754196


    e.g in Gnuplot it is possible



    plot "file.txt"using 2:7


    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?










    share|improve this question



























      0












      0








      0








      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.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



      ...




      and I need (the first numbers array):



           -0.818863

      -1.024597

      0.754196


      e.g in Gnuplot it is possible



      plot "file.txt"using 2:7


      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?










      share|improve this question
















      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.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



      ...




      and I need (the first numbers array):



           -0.818863

      -1.024597

      0.754196


      e.g in Gnuplot it is possible



      plot "file.txt"using 2:7


      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?







      arrays xcode






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 29 '18 at 8:28









      Cœur

      17.6k9105145




      17.6k9105145










      asked May 19 '14 at 22:50









      josefjosef

      1,5771516




      1,5771516
























          1 Answer
          1






          active

          oldest

          votes


















          0














          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]);
          }





          share|improve this answer
























          • thank you for helping. where should i write the path of the file that i have (file.txt)? and its showing me an error for [line componentsSeparatedByString:@" "]; > use of undeclared identifier "line"; did you mean "link"?

            – josef
            May 19 '14 at 23:22













          • any idea how to solve this error?

            – josef
            May 20 '14 at 17:05











          • For efficiently reading a file line by line check out this great answer stackoverflow.com/questions/3707427/…

            – Paul.s
            May 20 '14 at 19:38











          • thank you, i read it, even that it is for reading lines , i could complete my code from there. :) but i am getting now null please take a look on my new Question : link

            – josef
            May 20 '14 at 21:37













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f23748427%2fhow-to-get-from-a-file-txt-the-array-that-i-need-in-xcode%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          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]);
          }





          share|improve this answer
























          • thank you for helping. where should i write the path of the file that i have (file.txt)? and its showing me an error for [line componentsSeparatedByString:@" "]; > use of undeclared identifier "line"; did you mean "link"?

            – josef
            May 19 '14 at 23:22













          • any idea how to solve this error?

            – josef
            May 20 '14 at 17:05











          • For efficiently reading a file line by line check out this great answer stackoverflow.com/questions/3707427/…

            – Paul.s
            May 20 '14 at 19:38











          • thank you, i read it, even that it is for reading lines , i could complete my code from there. :) but i am getting now null please take a look on my new Question : link

            – josef
            May 20 '14 at 21:37


















          0














          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]);
          }





          share|improve this answer
























          • thank you for helping. where should i write the path of the file that i have (file.txt)? and its showing me an error for [line componentsSeparatedByString:@" "]; > use of undeclared identifier "line"; did you mean "link"?

            – josef
            May 19 '14 at 23:22













          • any idea how to solve this error?

            – josef
            May 20 '14 at 17:05











          • For efficiently reading a file line by line check out this great answer stackoverflow.com/questions/3707427/…

            – Paul.s
            May 20 '14 at 19:38











          • thank you, i read it, even that it is for reading lines , i could complete my code from there. :) but i am getting now null please take a look on my new Question : link

            – josef
            May 20 '14 at 21:37
















          0












          0








          0







          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]);
          }





          share|improve this answer













          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]);
          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered May 19 '14 at 22:57









          Paul.sPaul.s

          35.9k55782




          35.9k55782













          • thank you for helping. where should i write the path of the file that i have (file.txt)? and its showing me an error for [line componentsSeparatedByString:@" "]; > use of undeclared identifier "line"; did you mean "link"?

            – josef
            May 19 '14 at 23:22













          • any idea how to solve this error?

            – josef
            May 20 '14 at 17:05











          • For efficiently reading a file line by line check out this great answer stackoverflow.com/questions/3707427/…

            – Paul.s
            May 20 '14 at 19:38











          • thank you, i read it, even that it is for reading lines , i could complete my code from there. :) but i am getting now null please take a look on my new Question : link

            – josef
            May 20 '14 at 21:37





















          • thank you for helping. where should i write the path of the file that i have (file.txt)? and its showing me an error for [line componentsSeparatedByString:@" "]; > use of undeclared identifier "line"; did you mean "link"?

            – josef
            May 19 '14 at 23:22













          • any idea how to solve this error?

            – josef
            May 20 '14 at 17:05











          • For efficiently reading a file line by line check out this great answer stackoverflow.com/questions/3707427/…

            – Paul.s
            May 20 '14 at 19:38











          • thank you, i read it, even that it is for reading lines , i could complete my code from there. :) but i am getting now null please take a look on my new Question : link

            – josef
            May 20 '14 at 21:37



















          thank you for helping. where should i write the path of the file that i have (file.txt)? and its showing me an error for [line componentsSeparatedByString:@" "]; > use of undeclared identifier "line"; did you mean "link"?

          – josef
          May 19 '14 at 23:22







          thank you for helping. where should i write the path of the file that i have (file.txt)? and its showing me an error for [line componentsSeparatedByString:@" "]; > use of undeclared identifier "line"; did you mean "link"?

          – josef
          May 19 '14 at 23:22















          any idea how to solve this error?

          – josef
          May 20 '14 at 17:05





          any idea how to solve this error?

          – josef
          May 20 '14 at 17:05













          For efficiently reading a file line by line check out this great answer stackoverflow.com/questions/3707427/…

          – Paul.s
          May 20 '14 at 19:38





          For efficiently reading a file line by line check out this great answer stackoverflow.com/questions/3707427/…

          – Paul.s
          May 20 '14 at 19:38













          thank you, i read it, even that it is for reading lines , i could complete my code from there. :) but i am getting now null please take a look on my new Question : link

          – josef
          May 20 '14 at 21:37







          thank you, i read it, even that it is for reading lines , i could complete my code from there. :) but i am getting now null please take a look on my new Question : link

          – josef
          May 20 '14 at 21:37




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f23748427%2fhow-to-get-from-a-file-txt-the-array-that-i-need-in-xcode%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Mossoró

          Error while reading .h5 file using the rhdf5 package in R

          Pushsharp Apns notification error: 'InvalidToken'