MATLAB Answers


How to plot multiple values of a variable in one graph?

Asked by James Sheldon on 12 Jun 2018 at 17:36
Latest activity Commented on by James Sheldon on 20 Jun 2018 at 18:56

I put 5 txt files into a loop to graph the FFT and PDS continuously. They are audio files converted to txt files. I used "findpeaks" to find all peaks in the graphs. I then used "max" to find the max peak in each of the 5 graphs. I got 5 answers for the same variable. (l=max(v)). How do I plot all of these answers in one graph? Below is an example of my work. Here is the values I received for the max for each graph, l = 7.1537e+08, l = 1.3054e+09, l = 2.4736e+09, l = 3.4960e+09, l = 2.4039e+09

 numfiles = 5;
y = cell(1, numfiles);
for k = 1:numfiles
  myfilename = sprintf('file%d.txt', k);
  y{k} = importdata(myfilename);
v= pwelch(y{k})
xlim([0 4000])
l= max(v)


To clarify, you want to plot the maximum value (you call it l). What are you plotting it against? Index of the file?

Sign in to comment.

2 Answers

Answer by Arun Mathamkode on 15 Jun 2018 at 5:47

I believe you want to plot the maximum value for each graph against the index file. You can simply store maximum values in l as an array and plot the array.

In the loop, change l=max(v) to l(k)=max(v) and use plot(l) after the loop.


This is not exactly what I want. I want to plot the values in a somewhat waterfall type graph so I can stack up numerous values against one another to find the peak value. I will use this to set limits. So I want to plot each 1 values against the max height reached.

I want more of a scatter plot of the data so I can compare the results.

Sign in to comment.

Answer by James Sheldon on 19 Jun 2018 at 12:23

Okay. I will try that and see how it turns out. Thank you.


Sign in to comment.

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today