% Plotting Data from Excel
% K. A. Connor

% Input Data from Excel for a Laplace's Equation Solution
% First, you need to know what part of the excel file holds your data
% Second, copy the file into the Matlab Workspace so you have access to it
% V=xlsread('file.xls','upper left cell: lower right cell');

% Name the array (usually some kind of voltage)
vsb=xlsread('square_blob.xls','a1:cw101');

% Position array for plotting
d=size(vsb);
[x,y]=meshgrid(0:(d(1)-1)/100:(d(1)-1),0:(d(2)-1)/100:(d(2)-1));

% Calculate the E field using the gradient function
% [Ex,Ey]=gradient(-V);%Don't forget the negative sign 
[ex,ey]=gradient(-vsb);

% For streamlines one needs to specify where they should start
% It is a good idea to start them uniformly distributed around the largest
% electrode. [sx,sy]=meshgrid(0:100,1); %Note that the range of points is
% shown in one or the other of the parameters.;
[sx,sy]=meshgrid(0:5:100,1);
% Also want to start the field lines at the other electrode to check the
% accuracy of the method. Some inconsistencies will be observed. 
[tx,ty]=meshgrid(0:5:100,99);

% Plotting
contour(x,y,vsb,19);hold on;axis square;
% The following line does not work
%surface(x,y,vsb);shading interp;hold on;axis square;
g=streamline(ex,ey,sx,sy);set(g, 'Color', 'green');
% Green starts at the bottom and red at the top
h=streamline(-ex,-ey,tx,ty);set(h, 'Color', 'red');

% Generally, it appears that the better accuracy is achieved by starting at
% the electrode with the higher voltage. 

