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

Add custom legend without any relation to the graph

This is how I have solved this problem in the past: figure t=linspace(0,10,100); plot(t,sin(t)); hold on; h = zeros(3, 1); h(1) = plot(NaN,NaN,’or’); h(2) = plot(NaN,NaN,’ob’); h(3) = plot(NaN,NaN,’ok’); legend(h, ‘red’,’blue’,’black’); This will plot the additional points, but because the coordinates are at NaN they will not be visible on the plot itself: EDIT 26/10/2016: … Read more

Setting graph figure size

The properties that can be set for a figure is referenced here. You could then use: figure_number = 1; x = 0; % Screen position y = 0; % Screen position width = 600; % Width of figure height = 400; % Height of figure (by default in pixels) figure(figure_number, ‘Position’, [x y width height]);

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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)