# Matlab

# Spaces in strings in matlab/octave

To get spaces in the strings to work in matlab or octave, use t1={‘test test’} Result is t1 = { [1,1] = test test } t2=strcat({‘test test ‘},{‘blah blah’}) Result is t2 = { [1,1] = test test blah blah } you can use this string in your figures by plot([1:4]) title(t2{})

# All entries of array except certain indices in octave/matlab

In Octave or Matlab, some times one needs to eliminate certain elements in an array. For example, if a=[10,20,30,40,50,60]; and suppose I want to create a matrix “b” such that it has all the elements of “a” except 20 and 40. This can be achieved by: b=a(1:end~=2&1:end~=4); The result is: b = 10 Read More …

# Plasmonic materials in MEEP

The aim of this post is to share my experience in incorporating dielectric function of metals such as gold and silver into MEEP (a free finite difference time domain package) code. The incorporation is not an easy task and can be daunting for the first time user. Metals such as gold and silver have Read More …

# Adding a title to colobar in Matlab

To insert a title to the colorbar in matlab. Use the following code(Source): load mandrill % Loads a data for the example image(X) % Plots an image for the example t=colorbar;% Inserts a colorbar. a handle is created set(get(t,’ylabel’),’string’,’My colorbar title’,’Fontsize’,10) % sets the ylabel property of the handle t.

# Radiation from an oscillating dipole

The electric field from an oscillating dipole is given by:, where is the position vector, is the frequency of dipole oscillation, is the dipole moment. The two terms in the electric field consists of 1) near field (area near to the dipole) and 2) far field (area far from the dipole) contributions. Far field falls Read More …

# Smooth image in matlab

In matlab, sometimes I prefer to plot a image for mesh data instead of surf and use view(2) (view(2) gives the top view of the surface plot). However, imagesc(x,y,z) shading ‘interp’ does not work. This problem can be solved by using: pcolor(x,y,z) shading ‘interp’ set(gca,’TickDir’,’out’) .