I want to plot audio files in Vertically

i want to plot audio files in vertically...please refer the attachment.....please help me to solve this...

 Accepted Answer

See if the strips function will produce the desired result.
.

9 Comments

Thank you so much
As always, my pleasure!
.
Hi, may i get one more help......I have 30 audio files in a folder. There for i want to plot them all in vertically(strips)
See the documentation section on Import or Export a Sequence of Files to import them.
Then use strips with each one. Unless they are short files, I do not recommend putting all of them in one strips plot, since the resulting plot will be unreadable.
However if putting them all in one plot is the objective, it would be easiest to vertically concatenate them first, then do the plot, assuming that they are all using the same sampling frequency. If they use different sampling frequencies, first use the resample function to create a matrix with a uniform sampling frequency for all the files.
.
@Star Strider This is my code, can you guide me to clear the correction in my code please....
disp('entered')
disp(' Test run')
disp('Entered');
workspace; % Make sure the workspace panel is showing.
fontSize = 13;
% Specify the folder where the files live (unless a valid folder is hard coded in).
CHDFolder = '-'; %'D:\My Music\My Albums\Led Zeppelin\Early Days- The Best of Led Zeppelin, Vol. 1'; % Most awesome rock band of all time.
% Check to make sure that folder actually exists. Tell user to pick a folder if the folder doesn't exist.
disp('Entered');
if ~isfolder(CHDFolder)
promptMessage = sprintf('On the next window, please specify your folder of CHD Audio files.');
titleBarCaption = 'Folder?';
buttonText = questdlg(promptMessage, titleBarCaption, 'Continue', 'Quit', 'Continue');
if contains(buttonText, 'Quit')
return;
end
CHDFolder = uigetdir(CHDFolder);
if CHDFolder == 0
% User clicked Cancel.
return;
end
end
% Create a figure for the plots with the folder name at the top middle.
hFig = figure;
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.1, 1, 0.9]);
% Get rid of tool bar and pulldown menus that are along top of figure.
% set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'This program was written by ImageAnalyst', 'NumberTitle', 'Off')
textLabel = uicontrol('Style','text', 'Units', 'normalized', 'Position', [0, 0.95, 1, 0.05], 'FontSize', 16, ...
'String', CHDFolder, 'HorizontalAlignment', 'center');
% Get a list of all files in the folder with the desired file name pattern.
% First define the extension you want to use.
extension = '*.mp3','*.wav';
filePattern = fullfile(CHDFolder, extension); % Change to whatever pattern you need.
theFiles = dir(filePattern);
% Bail out, with an error message, if there are no music files in that folder.
numberOfFiles = length(theFiles);
if numberOfFiles == 0
errorMessage = sprintf('Error: No %s CHD Audo files were found in folder:\n%s', extension, CHDFolder);
uiwait(errordlg(errorMessage));
close(hFig);
return;
end
% Now loop over all files, reading them in and plotting their audio waveforms.
rows = ceil(sqrt(numberOfFiles));
fprintf(1,'please wait', 'Now reading from folder %s\n', CHDFolder);
for k = 1 : numberOfFiles
% Get the filename of the audio waveforms.
baseFileName = theFiles(k).name;
fullFileName = fullfile(CHDFolder, baseFileName);
fprintf(1, ' Now reading "%s"\n','please wait', baseFileName);
% Read the audio waveforms.
[y, fs] = audioread(fullFileName);
numfiles = 20;
mydata = cell(1, numfiles);
for k = 1:numfiles
myfilename = sprintf('file%d.mp3', k);
mydata{k} = importdata(myfilename);
end
% To read all files that match *.jpg with imread:
audioFiles = dir('*.mp3');
numfiles = length(audioFiles);
mydata = cell(1, numfiles);
for k = 1:numfiles
mydata{k} = imread(audioFiles(k).name);
end
end
What is wrong with it?
I cannot run it to test it.
function multiple_chd_Callback(hObject, eventdata, handles)
% hObject handle to multiple_chd (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Plots the audio waveforms of all the songs in a folder.
% By Image Analyst
% Defaults to MP3 extension files, but you can adapt it to handle any extension you want. Or even multiple extensions if you add code to do that.
% Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
fontSize = 13;
% Specify the folder where the files live (unless a valid folder is hard coded in).
CHDFolder = '-'; %'D:\My Music\My Albums\Led Zeppelin\Early Days- The Best of Led Zeppelin, Vol. 1'; % Most awesome rock band of all time.
% Check to make sure that folder actually exists. Tell user to pick a folder if the folder doesn't exist.
disp('Entered');
if ~isfolder(CHDFolder)
promptMessage = sprintf('On the next window, please specify your folder of CHD Audio files.');
titleBarCaption = 'Folder?';
buttonText = questdlg(promptMessage, titleBarCaption, 'Continue', 'Quit', 'Continue');
if contains(buttonText, 'Quit')
return;
end
CHDFolder = uigetdir(CHDFolder);
if CHDFolder == 0
% User clicked Cancel.
return;
end
end
% Create a figure for the plots with the folder name at the top middle.
hFig = figure;
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.1, 1, 0.9]);
% Get rid of tool bar and pulldown menus that are along top of figure.
% set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'This program was written by DEEPU', 'NumberTitle', 'Off')
textLabel = uicontrol('Style','text', 'Units', 'normalized', 'Position', [0, 0.95, 1, 0.05], 'FontSize', 16, ...
'String', CHDFolder, 'HorizontalAlignment', 'center');
% Get a list of all files in the folder with the desired file name pattern.
% First define the extension you want to use.
extension = '*.mp3','*.wav';
filePattern = fullfile(CHDFolder, extension); % Change to whatever pattern you need.
theFiles = dir(filePattern);
% Bail out, with an error message, if there are no music files in that folder.
numberOfFiles = length(theFiles);
if numberOfFiles == 0
errorMessage = sprintf('Error: No %s CHD Audo files were found in folder:\n%s', extension, CHDFolder);
uiwait(errordlg(errorMessage));
close(hFig);
return;
end
% Now loop over all files, reading them in and plotting their audio waveforms.
rows = ceil(sqrt(numberOfFiles));
fprintf(1,'please wait', 'Now reading from folder %s\n', CHDFolder);
for k = 1 : numberOfFiles
% Get the filename of the audio waveforms.
baseFileName = theFiles(k).name;
fullFileName = fullfile(CHDFolder, baseFileName);
fprintf(1, ' Now reading "%s"\n','please wait', baseFileName);
% Read the audio waveforms.
[y, fs] = audioread(fullFileName);
%------------------------------------------------------------------------------
% Plot the waveform.
subplot(rows, rows, k);
tDouble = (1 : length(y)) / fs; % Get time axis as a double. Convert number of elements into actual seconds (still a double though).
tDouble = tDouble / 60; % Convert to minutes (still a double though).
tMin = datetime(0,0,0) + minutes(tDouble); % Convert variable class from "double" to "duration".
plot(tMin, y(:, 1)); % Display waveform.
%------------------------------------------------------------------------------
% Make the plot fancy.
% Make the time axis show up in mm:ss format
ax = gca;
% xt = datetime(0,0,0) + minutes(0 : 0.5 : max(tDouble)); % Tick marks every 30 seconds.
xt = datetime(0,0,0) + minutes(0 : 1 : max(tDouble)); % Tick marks every 1 minute.
xticks(xt);
xtickformat('m:ss');
ax.XTickLabel = ax.XTickLabel;
xlabel('Time');
grid on;
title(baseFileName, 'FontSize', fontSize);
% Have it end on the last element, not necessarily on minute boundaries.
xlim([datetime(0,0,0), tMin(end)]);
ylim([-1, 1]);
drawnow; % Force display to update immediately.
end
As I wrote previously —
What is wrong with it?
I cannot run it to test it.
If it throws an error, please copy and paste all the red text from the Command Window to a Comment here.
If it does not throw an error, please describe what it is doing that it should not do, or what it is not doing that it should do, and the part of the code that is causing those problems.
The code is too long and too complicated for me to read it and determine if there are any problems (I might miss them because my experience with App Designer is extremely limited since I have no reason to build Apps), and I cannot run it to test it because I do not have access to your computer, where the files that it works with are located.
I will be glad to help as much as I can, however I need to know what the problem is with the code.
.

Sign in to comment.

More Answers (1)

function C_Test_Callback(hObject, eventdata, handles)
% hObject handle to C_Test (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
disp('entered')
disp(' Test run')
disp('Entered');
workspace; % Make sure the workspace panel is showing.
fontSize = 13;
% Specify the folder where the files live (unless a valid folder is hard coded in).
CHDFolder = '-'; %'D:\My Music\My Albums\Led Zeppelin\Early Days- The Best of Led Zeppelin, Vol. 1'; % Most awesome rock band of all time.
% Check to make sure that folder actually exists. Tell user to pick a folder if the folder doesn't exist.
disp('Entered');
if ~isfolder(CHDFolder)
promptMessage = sprintf('On the next window, please specify your folder of CHD Audio files.');
titleBarCaption = 'Folder?';
buttonText = questdlg(promptMessage, titleBarCaption, 'Continue', 'Quit', 'Continue');
if contains(buttonText, 'Quit')
return;
end
CHDFolder = uigetdir(CHDFolder);
if CHDFolder == 0
% User clicked Cancel.
return;
end
end
% Create a figure for the plots with the folder name at the top middle.
hFig = figure;
% c =uicontrol(VerticalAlignment);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.1, 1, 0.9]);
% Get rid of tool bar and pulldown menus that are along top of figure.
% set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
% vAlignObj = VAlign()
set(gcf, 'Name', 'This program was written by DEEPU', 'NumberTitle', 'Off')
textLabel = uicontrol('Style','text', 'Units', 'normalized', 'Position', [0, 0.95, 1, 0.05], 'FontSize', 16, ...
'String', CHDFolder, 'verticalalignment', 'center');
% Get a list of all files in the folder with the desired file name pattern.
% First define the extension you want to use.
extension = '*.mp3','*.wav';
filePattern = fullfile(CHDFolder, extension); % Change to whatever pattern you need.
theFiles = dir(filePattern);
% Bail out, with an error message, if there are no music files in that folder.
numberOfFiles = length(theFiles);
if numberOfFiles == 0
errorMessage = sprintf('Error: No %s CHD Audo files were found in folder:\n%s', extension, CHDFolder);
uiwait(errordlg(errorMessage));
close(hFig);
return;
end
% Now loop over all files, reading them in and plotting their audio waveforms.
rows = ceil(sqrt(numberOfFiles));
fprintf(1,'please wait', 'Now reading from folder %s\n', CHDFolder);
for k = 1 : numberOfFiles
% Get the filename of the audio waveforms.
baseFileName = theFiles(k).name;
fullFileName = fullfile(CHDFolder, baseFileName);
fprintf(1, ' Now reading "%s"\n','please wait', baseFileName);
% Read the audio waveforms.
[y, fs] = audioread(fullFileName);
%------------------------------------------------------------------------------
% Plot the waveform.
subplot(rows, rows, k);
tDouble = (1 : length(y)) / fs; % Get time axis as a double. Convert number of elements into actual seconds (still a double though).
tDouble = tDouble / 60; % Convert to minutes (still a double though).
tMin = datetime(0,0,0) + minutes(tDouble); % Convert variable class from "double" to "duration".
plot(tMin, y(:, 1)); % Display waveform.
%------------------------------------------------------------------------------
% Make the plot fancy.
% Make the time axis show up in mm:ss format
ax = gca;
% xt = datetime(0,0,0) + minutes(0 : 0.5 : max(tDouble)); % Tick marks every 30 seconds.
xt = datetime(0,0,0) + minutes(0 : 1 : max(tDouble)); % Tick marks every 1 minute.
xticks(xt);
xtickformat('m:ss');
ax.XTickLabel = ax.XTickLabel;
xlabel('Time');
grid on;
title(baseFileName, 'FontSize', fontSize);
% Have it end on the last element, not necessarily on minute boundaries.
xlim([datetime(0,0,0), tMin(end)]);
ylim([-1, 1]);
drawnow; % Force display to update immediately.
end
entered
Test run
Entered
Entered
Error using uicontrol
There is no verticalalignment property on the UIControl class.
Error in EEG_SCT>C_Test_Callback (line 10603)
textLabel = uicontrol('Style','text', 'Units', 'normalized', 'Position', [0, 0.95, 1, 0.05], 'FontSize', 16, ...
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in EEG_SCT (line 37)
gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)EEG_SCT('C_Test_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating Menu Callback.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!