Automatically plot different colored lines

You could use a colormap such as HSV to generate a set of colors. For example: cc=hsv(12); figure; hold on; for i=1:12 plot([0 1],[0 i],’color’,cc(i,:)); end MATLAB has 13 different named colormaps (‘doc colormap’ lists them all). Another option for plotting lines in different colors is to use the LineStyleOrder property; see Defining the Color … Read more

How should I update the data of a plot in Matlab?

Short answer : always use Set(‘Xdata’,…’). Example code: function PlotUpdate() x = 0:.1:8; y = sin(x); h = plot(x,y); y = sin(x.^3); set(h,’XData’,x,’YData’,y); end Long answer: There are three relevant measures by which one should choose the best method. Code clarity – How easy it is for someone to read your code? Runtime – How … Read more

How to draw a Histogram in Matlab

This should work just fine if you don’t want to use some predefined functions: una=unique(a); normhist=hist(a,size(unique(a),2))/sum(hist(a)); figure, stairs(una,normhist) Una has only the unique values of a, normhist is now between 0 and 1 and it’s the probability of occurring of the individual signal because you divide it by the number of elements included in the … Read more