How to fix subplot instant of tiledlayout.i'm using 2018 version MATLAB

first of all i'm using 2018 version of MATLAB. when i excute below program an unexpected error occuring...........please help me to fix this
guidata(hObject, handles);
disp('Entered');
guidata(hObject, handles);
folder_name = uigetdir('','Select src data Directory');
if isequal(folder_name,0)
disp('Directory Selected');
else
% set(handles.EEGFilename,'string','Wait Loading File.......');
disp(['You have selected ', fullfile(folder_name)]);
disp('CHD Audio file processing wait')
handles.srcFolder= fullfile(folder_name);
% set(handles.edDirName,'string',handles.srcFolder);
end
guidata(hObject, handles);
% Specify the folder where the files live.
k='';
myFolder = 'F:\audio';
folder ='F:\';
% AudioArray{k} = audioread(fullfile(folder));
% maxaudio(k) = max(AudioArray{k});
% myFolder = 'F:\audio';
% Check to make sure that folder actually exists. Warn user if it doesn't.
if ~isfolder(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s\nPlease specify a new folder.', myFolder);
uiwait(warndlg(errorMessage));
myFolder = uigetdir(); % Ask for a new one.
if myFolder == 0
% User clicked Cancel
return;
end
end
% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, '**/*.wav'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(theFiles(k).folder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
% Now do whatever you want with this file name,
% such as reading it in as an image array with imread()
AudioArray = audioread(fullFileName);
[y,fs] = audioread(fullFileName);
subplot = 'theFiles';
tiledlayout('flow')
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(theFiles(k).folder, baseFileName);
% read the file with audioread
[y,fs]=audioread(fullFileName);
% this defines a time variable for your x axis:
t = linspace(0, height(y)/fs, height(y));
% this adds another tile (axes) to your layout
nexttile
% plot it
plot(t,y)
% label it
xlabel('Time (s)')
ylabel('Amplitude')
set(gcf,'MenuBar','none')
end
ERROR
undefined function or variable 'tiledlayout'.

 Réponse acceptée

tiledlayout was introduced in R2019b. To fix use subplot() like Walter showed you. Also, have your inner loop be over k2 instead of k.

Plus de réponses (1)

guidata(hObject, handles);
disp('Entered');
guidata(hObject, handles);
folder_name = uigetdir('','Select src data Directory');
if isequal(folder_name,0)
disp('Directory Selected');
else
% set(handles.EEGFilename,'string','Wait Loading File.......');
disp(['You have selected ', fullfile(folder_name)]);
disp('CHD Audio file processing wait')
handles.srcFolder= fullfile(folder_name);
% set(handles.edDirName,'string',handles.srcFolder);
end
guidata(hObject, handles);
% Specify the folder where the files live.
k='';
myFolder = 'F:\audio';
folder ='F:\';
% AudioArray{k} = audioread(fullfile(folder));
% maxaudio(k) = max(AudioArray{k});
% myFolder = 'F:\audio';
% Check to make sure that folder actually exists. Warn user if it doesn't.
if ~isfolder(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s\nPlease specify a new folder.', myFolder);
uiwait(warndlg(errorMessage));
myFolder = uigetdir(); % Ask for a new one.
if myFolder == 0
% User clicked Cancel
return;
end
end
% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, '**/*.wav'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
numfiles = length(theFiles);
for k = 1 : numfiles
baseFileName = theFiles(k).name;
fullFileName = fullfile(theFiles(k).folder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
% Now do whatever you want with this file name,
% such as reading it in as an image array with imread()
AudioArray = audioread(fullFileName);
[y,fs] = audioread(fullFileName);
k_copy = k;
for k = 1 : numfiles
baseFileName = theFiles(k).name;
fullFileName = fullfile(theFiles(k).folder, baseFileName);
% read the file with audioread
[y,fs]=audioread(fullFileName);
% this defines a time variable for your x axis:
t = linspace(0, height(y)/fs, height(y));
subplot(numfiles, numfiles, (k_copy - 1)*numfiles + k);
% plot it
plot(t,y)
% label it
xlabel('Time (s)')
ylabel('Amplitude')
set(gcf,'MenuBar','none')
end
end

8 commentaires

Why are you plotting each file multiple times ???
Your outer k loop loops over all of the files, and your inner k loop (same variable name!!) loops over all of the files. So for example the second file will get plotted when the outer loop has just read the first file, when the inner loop reads the second file. Then the second file will get plotted again when the outer loop has just read the second file, ignored what it read, and reads the first file. And so on. So if you had 7 files, you would plot a 7 x 7 matrix in which the first column was all copies of the plot for the first file, the second column was all copies of the plot for the second file, and so on.
It is bad programming practice to use the same variable name for nested for loops: it becomes too easy to get confused about whether you are referring to the variable value in the outer loop, or the variable value in the inner loop.
Undefined function 'height' for input arguments of type 'double'.
This error showing,when i perform above program....please help me
height is fairly new. You probably have an old version of MATLAB so either upgrade or use size
numRows = size(yourArray, 1); % Equivalent to numRows = height(yourArray);
hi how to define my array here....i'm new to matlab please help
You have not defined / documented what the program is intended to do .
If you had explained your thoughts behind using nested loops reading the files, then we might have been able to suggest alternatives for what you thought you were doing.
right i'm doing like i want to plot all readed audio files to plot in a window.
The main problem i'm using 2018 Matlab.
in other words
I want to plot multiple audio files ina single window
please help me>>>>>>
They should all go in the same window. If you want them all in the same axes in the same window, just don't use subplot().
Here is my File Exchange for plotting all audio waveforms in a single window:
Thank you much brother .............................

Connectez-vous pour commenter.

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by