How to plot audiofiles in Vertically
이전 댓글 표시
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
The above shown is my code when i run it shows error like this
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.
답변 (1개)
Rik
2021년 11월 9일
0 개 추천
There is no VerticalAlignment property for uicontrol objects (neither in R2018a or R2021b). A center alignment is the default. For other object with such a property this is generally called middle.
There is a property HorizontalAlignment. The default value is center, so you don't need to specify it.
카테고리
도움말 센터 및 File Exchange에서 Get Started with Signal Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
