MATLAB - Read multiple *.log files, calculate and save as .*txt in new folder












-1















I make different measures and save it like *.log files, calculate it and save as .*txt.



%Filtering log files 
l = dir('*.log');

%Array size detection
[rows cols] = size(l);

%Choose a last file
file_name = strcat(strcat(l(rows).folder,'/'),l(rows).name)

%Reading log last file
fileread = fopen(file_name);

%Convert to float
times = fread(fileread,'float32');

%Filtering times and set to 0 small values
times(times<1e-8)=0;

%Set right times values
times_s = times * 1.0e-06;

%Solve full rotation speed (Hz)
motorspeed_full = 1./(2.*times_s)

%Filtering inf values and set to 0
motorspeed_full(motorspeed_full>1e+10)=0;

%Solve half rotation speed (Hz)
motorspeed_half = 1./(times_s);

A = '.txt';

[filepath,name,ext] = fileparts(file_name);

Xfilename = cat(2,name,A);

dlmwrite(Xfilename,motorspeed_full,'precision','%.3f');


So, it's possible to choose a last file, calculating it and convert it to .*txt. So now, I have to make a calculation after every measure.



enter image description here



My aim is:




  • Making first 1...n measures (1...n - *.log's and wav's)

  • Calculating and saving 1...n *.log's to *.txt's (see picture)

  • Create folder with file_name (ex. 20181120_125713) and insert file_name.txt and file_name.wav into this folder structureAim


Questions:




  • How can I converting all *.log files to *.txt files using dlmwrite?


  • How can I create a new folder with file_name



    mkdir(name);




for all files?





  • How to move the files with same names to folder with same name? Name of folder changes every time, so i can't work with



    movefile source destination



    Thank you very much for any help :*)












share|improve this question




















  • 1





    You haven't asked a question!

    – Ander Biguri
    Nov 22 '18 at 10:25











  • Please clarify what your question is or what difficulties you have to reach your "aims" (objectives?)

    – Anthony
    Nov 22 '18 at 11:59











  • Oh, sorry, I change my text below now!

    – Fracture
    Nov 22 '18 at 12:59











  • We are not here to provide code, this is not the purpose if this page. If the question is "what is the code to do this" the answer is: we wont do it for you

    – Ander Biguri
    Nov 22 '18 at 13:56











  • Its not only about code, I need to know a principle to make changes on multiple files! I can allready: Calculate and save a txt-files. To move file in one new folder. But i want to work with multiple files: I have 1.log, 2.log, 3.log and 1.wav, 2.wav, 3wav. I need to create 1.txt, 2.txt, 3.txt. Now I want make a folder named "1" and move 1.txt and 1.wav inside. Then make folder named "2" and move 2.txt and 2.wav! And the same with 3..n

    – Fracture
    Nov 22 '18 at 14:15
















-1















I make different measures and save it like *.log files, calculate it and save as .*txt.



%Filtering log files 
l = dir('*.log');

%Array size detection
[rows cols] = size(l);

%Choose a last file
file_name = strcat(strcat(l(rows).folder,'/'),l(rows).name)

%Reading log last file
fileread = fopen(file_name);

%Convert to float
times = fread(fileread,'float32');

%Filtering times and set to 0 small values
times(times<1e-8)=0;

%Set right times values
times_s = times * 1.0e-06;

%Solve full rotation speed (Hz)
motorspeed_full = 1./(2.*times_s)

%Filtering inf values and set to 0
motorspeed_full(motorspeed_full>1e+10)=0;

%Solve half rotation speed (Hz)
motorspeed_half = 1./(times_s);

A = '.txt';

[filepath,name,ext] = fileparts(file_name);

Xfilename = cat(2,name,A);

dlmwrite(Xfilename,motorspeed_full,'precision','%.3f');


So, it's possible to choose a last file, calculating it and convert it to .*txt. So now, I have to make a calculation after every measure.



enter image description here



My aim is:




  • Making first 1...n measures (1...n - *.log's and wav's)

  • Calculating and saving 1...n *.log's to *.txt's (see picture)

  • Create folder with file_name (ex. 20181120_125713) and insert file_name.txt and file_name.wav into this folder structureAim


Questions:




  • How can I converting all *.log files to *.txt files using dlmwrite?


  • How can I create a new folder with file_name



    mkdir(name);




for all files?





  • How to move the files with same names to folder with same name? Name of folder changes every time, so i can't work with



    movefile source destination



    Thank you very much for any help :*)












share|improve this question




















  • 1





    You haven't asked a question!

    – Ander Biguri
    Nov 22 '18 at 10:25











  • Please clarify what your question is or what difficulties you have to reach your "aims" (objectives?)

    – Anthony
    Nov 22 '18 at 11:59











  • Oh, sorry, I change my text below now!

    – Fracture
    Nov 22 '18 at 12:59











  • We are not here to provide code, this is not the purpose if this page. If the question is "what is the code to do this" the answer is: we wont do it for you

    – Ander Biguri
    Nov 22 '18 at 13:56











  • Its not only about code, I need to know a principle to make changes on multiple files! I can allready: Calculate and save a txt-files. To move file in one new folder. But i want to work with multiple files: I have 1.log, 2.log, 3.log and 1.wav, 2.wav, 3wav. I need to create 1.txt, 2.txt, 3.txt. Now I want make a folder named "1" and move 1.txt and 1.wav inside. Then make folder named "2" and move 2.txt and 2.wav! And the same with 3..n

    – Fracture
    Nov 22 '18 at 14:15














-1












-1








-1


1






I make different measures and save it like *.log files, calculate it and save as .*txt.



%Filtering log files 
l = dir('*.log');

%Array size detection
[rows cols] = size(l);

%Choose a last file
file_name = strcat(strcat(l(rows).folder,'/'),l(rows).name)

%Reading log last file
fileread = fopen(file_name);

%Convert to float
times = fread(fileread,'float32');

%Filtering times and set to 0 small values
times(times<1e-8)=0;

%Set right times values
times_s = times * 1.0e-06;

%Solve full rotation speed (Hz)
motorspeed_full = 1./(2.*times_s)

%Filtering inf values and set to 0
motorspeed_full(motorspeed_full>1e+10)=0;

%Solve half rotation speed (Hz)
motorspeed_half = 1./(times_s);

A = '.txt';

[filepath,name,ext] = fileparts(file_name);

Xfilename = cat(2,name,A);

dlmwrite(Xfilename,motorspeed_full,'precision','%.3f');


So, it's possible to choose a last file, calculating it and convert it to .*txt. So now, I have to make a calculation after every measure.



enter image description here



My aim is:




  • Making first 1...n measures (1...n - *.log's and wav's)

  • Calculating and saving 1...n *.log's to *.txt's (see picture)

  • Create folder with file_name (ex. 20181120_125713) and insert file_name.txt and file_name.wav into this folder structureAim


Questions:




  • How can I converting all *.log files to *.txt files using dlmwrite?


  • How can I create a new folder with file_name



    mkdir(name);




for all files?





  • How to move the files with same names to folder with same name? Name of folder changes every time, so i can't work with



    movefile source destination



    Thank you very much for any help :*)












share|improve this question
















I make different measures and save it like *.log files, calculate it and save as .*txt.



%Filtering log files 
l = dir('*.log');

%Array size detection
[rows cols] = size(l);

%Choose a last file
file_name = strcat(strcat(l(rows).folder,'/'),l(rows).name)

%Reading log last file
fileread = fopen(file_name);

%Convert to float
times = fread(fileread,'float32');

%Filtering times and set to 0 small values
times(times<1e-8)=0;

%Set right times values
times_s = times * 1.0e-06;

%Solve full rotation speed (Hz)
motorspeed_full = 1./(2.*times_s)

%Filtering inf values and set to 0
motorspeed_full(motorspeed_full>1e+10)=0;

%Solve half rotation speed (Hz)
motorspeed_half = 1./(times_s);

A = '.txt';

[filepath,name,ext] = fileparts(file_name);

Xfilename = cat(2,name,A);

dlmwrite(Xfilename,motorspeed_full,'precision','%.3f');


So, it's possible to choose a last file, calculating it and convert it to .*txt. So now, I have to make a calculation after every measure.



enter image description here



My aim is:




  • Making first 1...n measures (1...n - *.log's and wav's)

  • Calculating and saving 1...n *.log's to *.txt's (see picture)

  • Create folder with file_name (ex. 20181120_125713) and insert file_name.txt and file_name.wav into this folder structureAim


Questions:




  • How can I converting all *.log files to *.txt files using dlmwrite?


  • How can I create a new folder with file_name



    mkdir(name);




for all files?





  • How to move the files with same names to folder with same name? Name of folder changes every time, so i can't work with



    movefile source destination



    Thank you very much for any help :*)









matlab file






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 14:45







Fracture

















asked Nov 22 '18 at 10:21









FractureFracture

154




154








  • 1





    You haven't asked a question!

    – Ander Biguri
    Nov 22 '18 at 10:25











  • Please clarify what your question is or what difficulties you have to reach your "aims" (objectives?)

    – Anthony
    Nov 22 '18 at 11:59











  • Oh, sorry, I change my text below now!

    – Fracture
    Nov 22 '18 at 12:59











  • We are not here to provide code, this is not the purpose if this page. If the question is "what is the code to do this" the answer is: we wont do it for you

    – Ander Biguri
    Nov 22 '18 at 13:56











  • Its not only about code, I need to know a principle to make changes on multiple files! I can allready: Calculate and save a txt-files. To move file in one new folder. But i want to work with multiple files: I have 1.log, 2.log, 3.log and 1.wav, 2.wav, 3wav. I need to create 1.txt, 2.txt, 3.txt. Now I want make a folder named "1" and move 1.txt and 1.wav inside. Then make folder named "2" and move 2.txt and 2.wav! And the same with 3..n

    – Fracture
    Nov 22 '18 at 14:15














  • 1





    You haven't asked a question!

    – Ander Biguri
    Nov 22 '18 at 10:25











  • Please clarify what your question is or what difficulties you have to reach your "aims" (objectives?)

    – Anthony
    Nov 22 '18 at 11:59











  • Oh, sorry, I change my text below now!

    – Fracture
    Nov 22 '18 at 12:59











  • We are not here to provide code, this is not the purpose if this page. If the question is "what is the code to do this" the answer is: we wont do it for you

    – Ander Biguri
    Nov 22 '18 at 13:56











  • Its not only about code, I need to know a principle to make changes on multiple files! I can allready: Calculate and save a txt-files. To move file in one new folder. But i want to work with multiple files: I have 1.log, 2.log, 3.log and 1.wav, 2.wav, 3wav. I need to create 1.txt, 2.txt, 3.txt. Now I want make a folder named "1" and move 1.txt and 1.wav inside. Then make folder named "2" and move 2.txt and 2.wav! And the same with 3..n

    – Fracture
    Nov 22 '18 at 14:15








1




1





You haven't asked a question!

– Ander Biguri
Nov 22 '18 at 10:25





You haven't asked a question!

– Ander Biguri
Nov 22 '18 at 10:25













Please clarify what your question is or what difficulties you have to reach your "aims" (objectives?)

– Anthony
Nov 22 '18 at 11:59





Please clarify what your question is or what difficulties you have to reach your "aims" (objectives?)

– Anthony
Nov 22 '18 at 11:59













Oh, sorry, I change my text below now!

– Fracture
Nov 22 '18 at 12:59





Oh, sorry, I change my text below now!

– Fracture
Nov 22 '18 at 12:59













We are not here to provide code, this is not the purpose if this page. If the question is "what is the code to do this" the answer is: we wont do it for you

– Ander Biguri
Nov 22 '18 at 13:56





We are not here to provide code, this is not the purpose if this page. If the question is "what is the code to do this" the answer is: we wont do it for you

– Ander Biguri
Nov 22 '18 at 13:56













Its not only about code, I need to know a principle to make changes on multiple files! I can allready: Calculate and save a txt-files. To move file in one new folder. But i want to work with multiple files: I have 1.log, 2.log, 3.log and 1.wav, 2.wav, 3wav. I need to create 1.txt, 2.txt, 3.txt. Now I want make a folder named "1" and move 1.txt and 1.wav inside. Then make folder named "2" and move 2.txt and 2.wav! And the same with 3..n

– Fracture
Nov 22 '18 at 14:15





Its not only about code, I need to know a principle to make changes on multiple files! I can allready: Calculate and save a txt-files. To move file in one new folder. But i want to work with multiple files: I have 1.log, 2.log, 3.log and 1.wav, 2.wav, 3wav. I need to create 1.txt, 2.txt, 3.txt. Now I want make a folder named "1" and move 1.txt and 1.wav inside. Then make folder named "2" and move 2.txt and 2.wav! And the same with 3..n

– Fracture
Nov 22 '18 at 14:15












1 Answer
1






active

oldest

votes


















0














Here is my solution. Maybe it can help somebody:



clear all;
clc;

%Filtering log files
l = dir('*.log');
for k = 1:length(l)
next_name = l(k).name

%Array size detection
[rows cols] = size(l);

%Choose a last file
file_name = next_name;

%Reading log last file
fileread = fopen(file_name);

%Convert to float
times = fread(fileread,'float32');

%Filtering times and set to 0 small values
times(times<1e-8)=0;

%Set right times values
times_s = times * 1.0e-06;

%Solve full rotation speed (Hz)
motorspeed_full = 1./(2.*times_s);

%Filtering inf values and set to 0
motorspeed_full(motorspeed_full>1e+10)=0;

%Solve half rotation speed (Hz)
motorspeed_half = 1./(times_s);

A = '.txt';

[filepath,name,ext] = fileparts(file_name);

Xfilename = [name,A];

mkdir(name)

dlmwrite([name,filesep,Xfilename],motorspeed_full,'precision','%.3f');
% [name,'.wav'],[name, file, name, '.wav']
movefile([name,'.wav'],[name, filesep, name, '.wav']);
end





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',
    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%2f53428728%2fmatlab-read-multiple-log-files-calculate-and-save-as-txt-in-new-folder%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














    Here is my solution. Maybe it can help somebody:



    clear all;
    clc;

    %Filtering log files
    l = dir('*.log');
    for k = 1:length(l)
    next_name = l(k).name

    %Array size detection
    [rows cols] = size(l);

    %Choose a last file
    file_name = next_name;

    %Reading log last file
    fileread = fopen(file_name);

    %Convert to float
    times = fread(fileread,'float32');

    %Filtering times and set to 0 small values
    times(times<1e-8)=0;

    %Set right times values
    times_s = times * 1.0e-06;

    %Solve full rotation speed (Hz)
    motorspeed_full = 1./(2.*times_s);

    %Filtering inf values and set to 0
    motorspeed_full(motorspeed_full>1e+10)=0;

    %Solve half rotation speed (Hz)
    motorspeed_half = 1./(times_s);

    A = '.txt';

    [filepath,name,ext] = fileparts(file_name);

    Xfilename = [name,A];

    mkdir(name)

    dlmwrite([name,filesep,Xfilename],motorspeed_full,'precision','%.3f');
    % [name,'.wav'],[name, file, name, '.wav']
    movefile([name,'.wav'],[name, filesep, name, '.wav']);
    end





    share|improve this answer






























      0














      Here is my solution. Maybe it can help somebody:



      clear all;
      clc;

      %Filtering log files
      l = dir('*.log');
      for k = 1:length(l)
      next_name = l(k).name

      %Array size detection
      [rows cols] = size(l);

      %Choose a last file
      file_name = next_name;

      %Reading log last file
      fileread = fopen(file_name);

      %Convert to float
      times = fread(fileread,'float32');

      %Filtering times and set to 0 small values
      times(times<1e-8)=0;

      %Set right times values
      times_s = times * 1.0e-06;

      %Solve full rotation speed (Hz)
      motorspeed_full = 1./(2.*times_s);

      %Filtering inf values and set to 0
      motorspeed_full(motorspeed_full>1e+10)=0;

      %Solve half rotation speed (Hz)
      motorspeed_half = 1./(times_s);

      A = '.txt';

      [filepath,name,ext] = fileparts(file_name);

      Xfilename = [name,A];

      mkdir(name)

      dlmwrite([name,filesep,Xfilename],motorspeed_full,'precision','%.3f');
      % [name,'.wav'],[name, file, name, '.wav']
      movefile([name,'.wav'],[name, filesep, name, '.wav']);
      end





      share|improve this answer




























        0












        0








        0







        Here is my solution. Maybe it can help somebody:



        clear all;
        clc;

        %Filtering log files
        l = dir('*.log');
        for k = 1:length(l)
        next_name = l(k).name

        %Array size detection
        [rows cols] = size(l);

        %Choose a last file
        file_name = next_name;

        %Reading log last file
        fileread = fopen(file_name);

        %Convert to float
        times = fread(fileread,'float32');

        %Filtering times and set to 0 small values
        times(times<1e-8)=0;

        %Set right times values
        times_s = times * 1.0e-06;

        %Solve full rotation speed (Hz)
        motorspeed_full = 1./(2.*times_s);

        %Filtering inf values and set to 0
        motorspeed_full(motorspeed_full>1e+10)=0;

        %Solve half rotation speed (Hz)
        motorspeed_half = 1./(times_s);

        A = '.txt';

        [filepath,name,ext] = fileparts(file_name);

        Xfilename = [name,A];

        mkdir(name)

        dlmwrite([name,filesep,Xfilename],motorspeed_full,'precision','%.3f');
        % [name,'.wav'],[name, file, name, '.wav']
        movefile([name,'.wav'],[name, filesep, name, '.wav']);
        end





        share|improve this answer















        Here is my solution. Maybe it can help somebody:



        clear all;
        clc;

        %Filtering log files
        l = dir('*.log');
        for k = 1:length(l)
        next_name = l(k).name

        %Array size detection
        [rows cols] = size(l);

        %Choose a last file
        file_name = next_name;

        %Reading log last file
        fileread = fopen(file_name);

        %Convert to float
        times = fread(fileread,'float32');

        %Filtering times and set to 0 small values
        times(times<1e-8)=0;

        %Set right times values
        times_s = times * 1.0e-06;

        %Solve full rotation speed (Hz)
        motorspeed_full = 1./(2.*times_s);

        %Filtering inf values and set to 0
        motorspeed_full(motorspeed_full>1e+10)=0;

        %Solve half rotation speed (Hz)
        motorspeed_half = 1./(times_s);

        A = '.txt';

        [filepath,name,ext] = fileparts(file_name);

        Xfilename = [name,A];

        mkdir(name)

        dlmwrite([name,filesep,Xfilename],motorspeed_full,'precision','%.3f');
        % [name,'.wav'],[name, file, name, '.wav']
        movefile([name,'.wav'],[name, filesep, name, '.wav']);
        end






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 29 '18 at 12:09









        EBH

        9,44332247




        9,44332247










        answered Nov 29 '18 at 10:41









        FractureFracture

        154




        154






























            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%2f53428728%2fmatlab-read-multiple-log-files-calculate-and-save-as-txt-in-new-folder%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

            Costa Masnaga

            Fotorealismo

            Create new schema in PostgreSQL using DBeaver