Effacer les filtres
Effacer les filtres

How to plot cell arrays in a for loop?

2 vues (au cours des 30 derniers jours)
Jose Peñaloza
Jose Peñaloza le 14 Août 2015
Commenté : dpb le 17 Août 2015
I want to plot different graphs after load data from .wav or .avi files. The problem is because information is organized in cells that contains other cells. I tried to make different types of code but it didn't work, the last part is the plot code. So I hope you can help me This is my code:
files= dir('*.wav')
numfiles=length(files)
mydata= cell(numfiles,1);
info=cell(numfiles,1)
isFileSupported = true(numfiles, 1) ;
for j=1:numfiles
try
info{j}=mmfileinfo(files(j).name)
audio = info{j}.Audio
video = info{j}.Video;
catch ME
isFileSupported(j) = false;
continue;
end
end
supportedFiles = files(isFileSupported);
for k=1:numel(supportedFiles)
mydata{k}=importdata(supportedFiles(k).name);
end
for j=1:numfiles
H=mydata{k};
x={:}
y={:}
plot(x,y)
end

Réponses (1)

dpb
dpb le 14 Août 2015
for k=1:numel(supportedFiles)
dat=importdata(supportedFiles(k).name);
figure % presume want a new figure for each file...
plot(dat(:,1), dat(:,2:end)) % presume 1st column is x, any others are to be plotted
end
  2 commentaires
Jose Peñaloza
Jose Peñaloza le 17 Août 2015
Hi!!! dpb I tried with your answer and the program showed me an error: ??? Error using ==> plot Not enough input arguments.
files= dir('*.avi')
numfiles=length(files)
mydata= cell(numfiles,1);
info=cell(numfiles,1)
isFileSupported = true(numfiles, 1) ;
for j=1:numfiles
try
info{j}= mmfileinfo(files(j).name);
audio = info{j}.Audio;
video = info{j}.Video;
catch ME
isFileSupported(j) = false;
continue;
end
end
supportedFiles = files(isFileSupported);
for k=1:numel(supportedFiles)
mydata{k}=importdata(supportedFiles(k).name);
end
for k=1:numel(supportedFiles)
dat=importdata(supportedFiles(k).name);
figure
plot(dat(:,1), dat(:,2:end))
end
Thanks in advance :)
dpb
dpb le 17 Août 2015
Use debugger and let us know what the result of numel(supportedFiles) and
which dat
after the importdata call. Needs must know what's you got; we have no data from which to work that lets us know what form any of the results are returned (or if any are, even).

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by