saving output of wavfile generating script on matlab - matlab

I have a wav file generating function and want to save the output of a loop containing this function to a folder as wav files.

What you need is the function wavwrite (http://www.mathworks.de/de/help/matlab/ref/wavwrite.html) ;-) I hope that helps you and makes it possible for you to save your files.

Related

How to open .cs file using Matlab?

I am working on compressing an image using compressive sensing.
I downloaded the code. I ran the demo_firstTry.m, demo_GAPTV.m and demo_read_CSfile_and_Reconstruct.m functions, they worked well.
The problem is that I need the compressed vector, it is saved as .cs file in the path written on the function,
I don't know how to open this file to get the compressed image vector ?
You can use MATLAB's inbuilt function cv.imread as below:
img = cv.imread(filename)
img = cv.imread(filename, 'OptionName',optionValue, ...)
This should solve the query.

How to convert .pgm file to .mat file in Matlab?

I have to convert 'Yale' dataset whose format is .pgm to .mat file, I searched about this issue but couldn't find anything.
I appreciate any help.
Images can be saved in .mat format by using the save() function offered by MATLAB.
Let us suppose the name of your image is xyz.pgm that has to be saved as xyz.mat. Following steps should do so :
im = imread('xyz.pgm')
save('xyz.mat','im')
You can look into save() function to learn more about it.
Instead if you just want to convert it into other image formats, you should look up imwrite().

MATLAB won't open a file created by Octave

I generated and saved large number of data files using Octave, and now I need to open them in MATLAB as part of analyzing them. MATLAB spits out this error.
Error using load
Unable to read MAT-file
[file path]/PhPar_40.mat: not a binary MAT-file.
Try LOAD -ASCII to read as text.
Trying its suggestion of load -ASCII then gives this error.
Error using load
Number of columns on line 2 of ASCII file
[filepath]/PhPar_40.mat must be the same as previous lines.
I (now) understand that Octave is capable of saving in a MATLAB readable format, but re-creating these data files would take an inordinate amount of time and really isn't an option. Is there a way to get MATLAB to read these files?
MATLAB can't open these files because these are not saved by octave properly. Try saving them in octave by following command:
save -mat7-binary '[filepath]/PhPar_40.mat' 'm'
If you have large number of files, you can place all files in folder and then run an iterator to read all load and save in correct format automatically. This iterator will look like:
file = dir('[filepath_read]/*.mat');
index = 1;
while (index==length(file)+1)
m = load('file(index).name')
save -mat7-binary strcat("[filepath_write]/", file(index).name, ".mat") 'm';
index = index+1;
pause(1);
endwhile
Once you have all the files converted to right format, load them in MATLAB. I hope it will solve your problem

How to generate multiple .wav files with different names by using matlab loop

How to generate multiple .wav files with different names by using a loop in MATLAB. Say that for example in the path folder have 10 .wav files.
files=dir('D:\...\...\*.wav');
z=[];
[d1,sr] = wavread('helo.wav');
for k=1:length(files);
file_name=files(k).name;
path=['D:\...\...\',file_name];
fprintf('processing %s\n',path);
[d2,sr]= wavread(path);
a=d1+d2;
end
Meaning all the .wav files in path folder will sum with by 'helo.wav' and save the output in 10 different, .wav files?
Well, I have to assume a number of things since you didn't tell us them, but the following lines will save each a to a file named by the loop index:
outfile = strcat('D:\...\...\',num2str(k),'.wav');
audiowrite(outfile,a,sr)

How can I convert a sound file to .mif using MATLAB?

I want to have a mif file from the sound signal of a for example mp3 file. How can I do it using MATLAB?
Thanks,
BooMZ!
As result, I couldn't find any solution to convert a MP3 file to mif. But I could convert wav file to mif. It's the instructions:
First you must drag and drop your wav file to MatLab. MatLab will make a array from wav file. Finally, you must write the data array to a file with mif format. (you can do it by fprintf)