Matlab template
% see also reading in data using matlab
% for figures, http://nibot-lab.livejournal.com/73290.html
% and http://saig.phys.ualberta.ca/toolbox/Matlab/making_figures.html
% suggestion: use a "startup.m" file for common settings
%{
Date
Description:
Name
%}
% for faster operations, run in CLI
% matlab -nodesktop -nosplash
fid=fopen('quasi1d_rect_parameters.input');
c=textscan(fid,'%s');
L=str2num(c{1}{21});
W=str2num(c{1}{22});
clear
clc
format long;
tic;
set(0,'DefaultAxesPosition',[0.17 0.17 0.75 0.75])
set(0,'DefaultTextInterpreter', 'latex')
set(0,'defaultaxesfontsize',20);
set(0,'defaultaxesfontname','times');
set(0,'defaultaxeslinewidth',1);
set(0,'defaultaxesbox','on');
set(0,'defaulttextfontname','times');
set(0,'defaulttextfontsize',20);
set(0,'defaulttextlinewidth',1);
set(0,'defaultlinelinewidth',2);
set(0,'defaultlinemarkersize',10);
% code
figure('Position',[0 -50 1200 400]); hold on;
subplot(2,1,1);pcolor(xm,ym,abs(E_pw(:,:)').^2); axis equal tight;shading flat;drawnow;
title(['field intensity, freq = ',num2str(freq(fli))]); xlabel('L/\lambda'); ylabel('W/\lambda');
subplot(2,1,2);plot(freq,ge(:,1)); hold on; axis([.99 1.01 1 3]);
plot(freq(fli),ge(fli,1),'MarkerSize',20,'Marker','.','Color',[1 0 0]);
xlabel('frequency'); ylabel('g')
%% Create figure
figure1 = figure;
input = load('filename.dat');
%% Create axes
axes1 = axes('FontName','Times New Roman','FontSize',20,'Parent',figure1);
xlabel(axes1,'x axis label');
ylabel(axes1,'y axis label');
box(axes1,'on');
hold(axes1,'all');
plot(inv_l_scat_Mello,'LineStyle','none','MarkerSize',15,'Marker','diamond','Color',[0 0 1],'DisplayName',['Mello, N=',num2str(N_chan)])
%% Create plot
plot1 = plot(y1,'LineWidth',2);
%to check a script, use
mlint('filename')
% colors:
[0 0 1]; % blue
[0 0.75 0.75]; % aqua
[1 0 0]; % red
[0.75 0 0.75]; % magenta
[0 0.5 0]; % green
[0.6 0.2 0]; % brown
[0.75 0.75 0]; % gold
[0 0 0]; % black
% suppose the dynamic range yields a very dark plot with colormap "hot"
pcolor(data); shading flat; axis equal tight; colormap(hot); draw now;
% occasionally, a simple log of the values does not help as desired
% if the values are [0 to 0.15]
pcolor(log(0.02+data)); shading flat; axis equal tight; colormap(hot); draw now;
figure('Visible','off');
plot3(X1,Y1,Z1,'Marker','.','LineStyle','none');
% if you have a simple matrix with integer sized labels,
surf(g,'LineStyle','none');
% if the matrix axis labels are not integer-sized, use a mesh grid
step=0.01;
[x,y]=meshgrid(0:step:size(plotme,2)*step-step,0:step:size(plotme,1)*step-step);
figure; pcolor(x,y,plotme); shading flat;
% this would be the default (integer step) grid:
[x,y]=meshgrid(1:size(plotme,2),1:size(plotme,1));
figure; pcolor(x,y,plotme); shading flat;
% if the vectors "dx" and "closed" be the vectors that describe the labels
[x,y]=meshgrid(closed,dx);
surf(x,y,plotme);
%{
figure(1);
plot(x,y);
title ('name');
xlabel('x');
ylabel('y');
%}
disp(['hello world',num2str(a),'asdf']);
%{
figure(2);
hold on;
plot(k,lambda,'r-'); % "r" = red, "-" = solid line
hold on;
plot([1.3 1.7],[0.002 0.002],'m--'); % how to plot a straight line,
% color magenta, dashed line
axis([1.3 1.7 0 0.05]); % how to set the plot window
hold on;
plot(k,abs(phase),'g-.'); % "g" = green, "-." = dash/dot line
%}
%flip the order of a vector:
ylr(:)=ylr(end:-1:1);
% append vectors:
a = load('folder\file1.dat');
b = load('folder\file2.dat');
c = [a b];
c = [a c]
% transpose
a = a'
view(200, 45);%view(az, el);
% note: "normal" 2D view is view(0,90);
% flip 2D top to bottom: view(0,270);
% flip 2D L to R view(180,270);
%pause
%stop
figure;
surf(freq(1:1000),abs(gain(1:20)),log(g(1:20,:)),'EdgeColor','none')
axes('FontName','Times New Roman','FontSize',30);
xlabel('hello', 'FontName','Times New Roman','FontSize',30);
ylabel('-gain');
zlabel('transmission');
title('transmission v. gain v. freq');
saveas(gcf, 'alpha_beta_1_v_gain', 'png')
saveas(gcf,[datestr(clock,'yyyymmdd') 'waveFunction_' num2str(m)],'png');
ylabel({'Transmission';'Energy'})
% can save 2D matrices as ascii,
save 'scat' g -ascii -double -tabs
save (['hello',num2str(4),'.dat'],'medium','-ascii')
% but not more than 2D
save 'data_from_run.mat'
figure(3);
semilogy(freq,(energy_lr))
hold on;
semilogy(freq,(energy_rl))
semilogy(freq,(transmission_lr))
semilogy(freq,(transmission_rl))
semilogy(freq,(transmission_lr./energy_lr))
semilogy(freq,(transmission_rl./energy_rl))
h = legend('energy_lr','energy_rl','transmission_lr','transmission_rl','transmission_lr/energy_lr','transmission_rl/energy_rl');
set(h,'Interpreter','none')
legend('hide')
toc