How to save a text file to a .mat file?











up vote
-1
down vote

favorite












How do I save a '.txt' file as a '.mat' file, using either MATLAB or Python?
I tried using textscan() (in MATLAB), and scipy.io.savemat() (in Python). Both didn't help.



My text file is of the format: value1,value2,value3,valu4 (each row) and has over 1000 rows.



Appreciate any help is appreciated. Thanks in advance.










share|improve this question


























    up vote
    -1
    down vote

    favorite












    How do I save a '.txt' file as a '.mat' file, using either MATLAB or Python?
    I tried using textscan() (in MATLAB), and scipy.io.savemat() (in Python). Both didn't help.



    My text file is of the format: value1,value2,value3,valu4 (each row) and has over 1000 rows.



    Appreciate any help is appreciated. Thanks in advance.










    share|improve this question
























      up vote
      -1
      down vote

      favorite









      up vote
      -1
      down vote

      favorite











      How do I save a '.txt' file as a '.mat' file, using either MATLAB or Python?
      I tried using textscan() (in MATLAB), and scipy.io.savemat() (in Python). Both didn't help.



      My text file is of the format: value1,value2,value3,valu4 (each row) and has over 1000 rows.



      Appreciate any help is appreciated. Thanks in advance.










      share|improve this question













      How do I save a '.txt' file as a '.mat' file, using either MATLAB or Python?
      I tried using textscan() (in MATLAB), and scipy.io.savemat() (in Python). Both didn't help.



      My text file is of the format: value1,value2,value3,valu4 (each row) and has over 1000 rows.



      Appreciate any help is appreciated. Thanks in advance.







      python-2.7 matlab text-files mat-file






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 2 days ago









      aiEvangelist

      86




      86
























          3 Answers
          3






          active

          oldest

          votes

















          up vote
          3
          down vote













          You can use textscan to read the file and save to save the variables into a .mat file



          fid = fopen('yourTextFile.txt');
          C = textscan(fid,'%f %f %f %f');
          fclose(fid);
          % maybe change the cells from `C` to a single matrix
          M = cell2mat(C);
          save('myMatFile.mat','M');


          This works because your file seems to have a fixed format.
          Have a look at this and this






          share|improve this answer





















          • When I run this, I get the following error:Error using cat Dimensions of matrices being concatenated are not consistent. Error in cell2mat (line 75) m{n} = cat(2,c{n,:});
            – aiEvangelist
            2 days ago












          • Can you please give more information about the content of your file and the dimension of each cell in C.
            – user7431005
            yesterday


















          up vote
          0
          down vote













          I was able to get it to work using csvread() as follows:



          file = csvread('yourTextFile.txt');
          save('myMatFile.mat','file');





          share|improve this answer




























            up vote
            -3
            down vote













            if what you need is to change file format:
            mv example.mat example.txt






            share|improve this answer





















              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',
              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%2f53203507%2fhow-to-save-a-text-file-to-a-mat-file%23new-answer', 'question_page');
              }
              );

              Post as a guest
































              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              3
              down vote













              You can use textscan to read the file and save to save the variables into a .mat file



              fid = fopen('yourTextFile.txt');
              C = textscan(fid,'%f %f %f %f');
              fclose(fid);
              % maybe change the cells from `C` to a single matrix
              M = cell2mat(C);
              save('myMatFile.mat','M');


              This works because your file seems to have a fixed format.
              Have a look at this and this






              share|improve this answer





















              • When I run this, I get the following error:Error using cat Dimensions of matrices being concatenated are not consistent. Error in cell2mat (line 75) m{n} = cat(2,c{n,:});
                – aiEvangelist
                2 days ago












              • Can you please give more information about the content of your file and the dimension of each cell in C.
                – user7431005
                yesterday















              up vote
              3
              down vote













              You can use textscan to read the file and save to save the variables into a .mat file



              fid = fopen('yourTextFile.txt');
              C = textscan(fid,'%f %f %f %f');
              fclose(fid);
              % maybe change the cells from `C` to a single matrix
              M = cell2mat(C);
              save('myMatFile.mat','M');


              This works because your file seems to have a fixed format.
              Have a look at this and this






              share|improve this answer





















              • When I run this, I get the following error:Error using cat Dimensions of matrices being concatenated are not consistent. Error in cell2mat (line 75) m{n} = cat(2,c{n,:});
                – aiEvangelist
                2 days ago












              • Can you please give more information about the content of your file and the dimension of each cell in C.
                – user7431005
                yesterday













              up vote
              3
              down vote










              up vote
              3
              down vote









              You can use textscan to read the file and save to save the variables into a .mat file



              fid = fopen('yourTextFile.txt');
              C = textscan(fid,'%f %f %f %f');
              fclose(fid);
              % maybe change the cells from `C` to a single matrix
              M = cell2mat(C);
              save('myMatFile.mat','M');


              This works because your file seems to have a fixed format.
              Have a look at this and this






              share|improve this answer












              You can use textscan to read the file and save to save the variables into a .mat file



              fid = fopen('yourTextFile.txt');
              C = textscan(fid,'%f %f %f %f');
              fclose(fid);
              % maybe change the cells from `C` to a single matrix
              M = cell2mat(C);
              save('myMatFile.mat','M');


              This works because your file seems to have a fixed format.
              Have a look at this and this







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered 2 days ago









              user7431005

              648114




              648114












              • When I run this, I get the following error:Error using cat Dimensions of matrices being concatenated are not consistent. Error in cell2mat (line 75) m{n} = cat(2,c{n,:});
                – aiEvangelist
                2 days ago












              • Can you please give more information about the content of your file and the dimension of each cell in C.
                – user7431005
                yesterday


















              • When I run this, I get the following error:Error using cat Dimensions of matrices being concatenated are not consistent. Error in cell2mat (line 75) m{n} = cat(2,c{n,:});
                – aiEvangelist
                2 days ago












              • Can you please give more information about the content of your file and the dimension of each cell in C.
                – user7431005
                yesterday
















              When I run this, I get the following error:Error using cat Dimensions of matrices being concatenated are not consistent. Error in cell2mat (line 75) m{n} = cat(2,c{n,:});
              – aiEvangelist
              2 days ago






              When I run this, I get the following error:Error using cat Dimensions of matrices being concatenated are not consistent. Error in cell2mat (line 75) m{n} = cat(2,c{n,:});
              – aiEvangelist
              2 days ago














              Can you please give more information about the content of your file and the dimension of each cell in C.
              – user7431005
              yesterday




              Can you please give more information about the content of your file and the dimension of each cell in C.
              – user7431005
              yesterday












              up vote
              0
              down vote













              I was able to get it to work using csvread() as follows:



              file = csvread('yourTextFile.txt');
              save('myMatFile.mat','file');





              share|improve this answer

























                up vote
                0
                down vote













                I was able to get it to work using csvread() as follows:



                file = csvread('yourTextFile.txt');
                save('myMatFile.mat','file');





                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  I was able to get it to work using csvread() as follows:



                  file = csvread('yourTextFile.txt');
                  save('myMatFile.mat','file');





                  share|improve this answer












                  I was able to get it to work using csvread() as follows:



                  file = csvread('yourTextFile.txt');
                  save('myMatFile.mat','file');






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 23 hours ago









                  aiEvangelist

                  86




                  86






















                      up vote
                      -3
                      down vote













                      if what you need is to change file format:
                      mv example.mat example.txt






                      share|improve this answer

























                        up vote
                        -3
                        down vote













                        if what you need is to change file format:
                        mv example.mat example.txt






                        share|improve this answer























                          up vote
                          -3
                          down vote










                          up vote
                          -3
                          down vote









                          if what you need is to change file format:
                          mv example.mat example.txt






                          share|improve this answer












                          if what you need is to change file format:
                          mv example.mat example.txt







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered 2 days ago









                          liaofeng

                          596




                          596






























                               

                              draft saved


                              draft discarded



















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53203507%2fhow-to-save-a-text-file-to-a-mat-file%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest




















































































                              Popular posts from this blog

                              Schultheiß

                              Verwaltungsgliederung Dänemarks

                              Liste der Kulturdenkmale in Wilsdruff