Navigation

    ask avan logo
    • Register
    • Login
    • Search
    • Categories
    • Unsolved
    • Solved

    Matlab : How can I automatically let Matlab input the file in sequence?

    Coding Question & Answers
    2
    5
    67
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Alan Daniel
      Alan Daniel last edited by avan

      How can I let Matlab automatically input the file itself rather than one by one myself?

      I mean, I want to put Sample 1.wav and then output Sample 1.png and then put Sample 2.wav and then output Sample 2.png and then put Sample 3.wav and then output Sample 3.png

      I do not want to type myself 1, 2, 3 and rather let the matlab run itself from 1 to 1,000

      [y,Fs] = audioread('sample1.wav');
      spectrogram(y,'yaxis')
      saveas(gcf,'sample1.png')
      Then
      
      [y,Fs] = audioread('sample2.wav');
      spectrogram(y,'yaxis')
      saveas(gcf,'sample2.png')
      Then
      
      [y,Fs] = audioread('sample3.wav');
      spectrogram(y,'yaxis')
      saveas(gcf,'sample3.png')
      
      Reply Quote 0
        1 Reply Last reply

      • avan
        avan last edited by

        Hey again @Alan-Daniel

        Don't forget to format your code using backticks ` 🙂

        With that said, I don't know Matlab but here is what I am thinking and found online:

        a='sample';
        b = 1;
        c='.wav';
        d='.png'
        while( b < 1000 )
             bstr = num2str(b);
             inputname = [a bstr c];
             outputname= [a bstr d]
            [y,Fs] = audioread(inputname);
            spectrogram(y,'yaxis')
            saveas(gcf,outputname)
             b = b + 1;
        end
        

        Again, I don't know Matlab and I don't have Matlab installed on my computer so the above code is untested and might need some adjusting! But the idea should be relative solid.

        Hope this works for you in some way. Let me know.

        Reply Quote 0
          1 Reply Last reply

        • avan
          avan last edited by

          Hey again @Alan-Daniel

          Don't forget to format your code using backticks ` 🙂

          With that said, I don't know Matlab but here is what I am thinking and found online:

          a='sample';
          b = 1;
          c='.wav';
          d='.png'
          while( b < 1000 )
               bstr = num2str(b);
               inputname = [a bstr c];
               outputname= [a bstr d]
              [y,Fs] = audioread(inputname);
              spectrogram(y,'yaxis')
              saveas(gcf,outputname)
               b = b + 1;
          end
          

          Again, I don't know Matlab and I don't have Matlab installed on my computer so the above code is untested and might need some adjusting! But the idea should be relative solid.

          Hope this works for you in some way. Let me know.

          Reply Quote 0
            1 Reply Last reply

          • Alan Daniel
            Alan Daniel last edited by

            it works, thanks!

            Reply Quote 1
              1 Reply Last reply

            • avan
              avan last edited by

              Awesome. Glad I can be of help.

              Reply Quote 0
                1 Reply Last reply

              • Alan Daniel
                Alan Daniel last edited by

                Thanks a lot. You are brillant!

                Reply Quote 1
                  1 Reply Last reply

                • First post
                  Last post