nav-left cat-right
cat-right

pcolor and contour plot with different colormaps

Matlab does not allow to combine use more than one colormap in a figure. However there are some possibilities to get around this problem, which are presented in this article. Initialization and export of figure For all plots the same initialization for the data and the figure is used: % clear command window, figures and all variables clc; clf; clear all;   %% Common variables   FontSize = 12; FontName =...

pcolor plots with publication ready formating

Matlab has many possibilities to create plots even fancy ones. However its defaults are very seldom suitable to use the plots directly for a publication. The following minimal code demonstrates how to generate a pcolor plot for 2D data with x- and y-axis. The data was calculated using the function shown here. pcolor(xAxis, yAxis, Data2D); shading flat; % do not interpolate pixels colorbar % add colorbar  ...

fast calculation of functions with two variables

If you come from the programming world of C/C++ or java or any other traditional programming languages you might fall into the trap of using for loops for the calculation of functions. This works as expected but it is much slower than what matlab can do. The following example demonstrates this principle (which you should not use if you can) Data2D = zeros([xPoints yPoints]); for xi = 1:xPoints x =...

plotting a filled curve

A search on how to fill the area under a curve reveals that such questions are quite often asked. Here is the solution in a function file that I created for simplifying filled curve plots using matlabs fill function. function handle = filledcurve(x, y, zero, colorspec)   if (nargin < 3) zero = 0; end   if (nargin < 4) colorspec = 'b'; end     xtemp = [x(1) ;...

fast reading of structured text data with matlab

In the following I present a solution to read data from a textfile which has the number of x-values (columns) in the first line, the number of y-values (rows) in the second line and in all following lines the matrix with size x times y. The principle reading of the data is achieved by the following code % open file display(['reading ' FILENAME]); fid = fopen(FILENAME, 'r'); fseek(fid, 0,...
Seite 2 von 3123