Archive for Code
- Matlab Image Correlation
- Create a Latin square in MATLAB
- Update Simulink variables from MATLAB GUI
- Matlab Quadratic Programming Optimisation Problem
- Matlab Shortest Path Optimisation Problem
- MATLAB updates Access database via SQL
- Matlab Material Blending Optimisation Problem
- Matlab Open Box Optimisation Problem
- Java Hello World
- Installing JOGL and configuring for Windows and Eclipse
Matlab Image Correlation
Visually Evoked Potentials (VEPs) are small changes in the brain signal cause by a visual stimulus. Responses are recorded using electroencephalogram (EEG) electrodes located near the occipital cortex, the area of the brain involved in receiving and interpreting visual signals. I used the following matlab code to check the correlation of images that were going to be used as stimuli for the EEG experiment.
I used the Corr2 function in Matlab. Corr2(A,B) computes the correlation coefficient between A and B, where A and B are matrices or vectors of the same size. Corr2 computes the correlation coefficient using the equation;

In case you want to try and type that into Latex
r = \frac{\sum_{m} \sum_{n}(A_{mn} - \bar{A}) (B_{mn} - \bar{B})}{\sqrt{\left ( \sum_{m} \sum_{n}(A_{mn} - \bar{A})^{2} \right ) \left ( \sum_{m} \sum_{n}(B_{mn} - \bar{B})^{2} \right )}}
Theres a handy Latex visual equation editor on the codecogs.com website.
Matlab Code
root ='C:\Users\Richard\Documents\My Dropbox\EXPERIMENTS\images\';
temp = (rgb2gray(imread([root 'FACE_v201.JPG'] ))); % Template Image to correlate against
for x=1:100
cc(x) = corr2(temp,(rgb2gray(imread([root 'FACE_v20' num2str(x) '.JPG'] )))); % correlate images
end
Matlab gives this example
I = imread(‘pout.tif’);
J = medfilt2(I);
R = corr2(I,J)
R =
0.9959
Create a Latin square in MATLAB
a Latin square is an n × n array filled with n different Latin letters, each occurring exactly once in each row and exactly once in each column.
Latin squares are used in statistics and in mathematics.
- In the design of experiments, Latin squares are a special case of row-column designs for two blocking factors:[1] Many row-column designs are constructed by concatenating Latin squares.[2]
- In algebra, Latin squares are generalizations of groups; in fact, Latin squares are characterized as being the multiplication tables (Cayley tables) of quasigroups.
% Generate a Latin Square
% =============================
% for Matlab R13
% version 1.0 (feb 2010)
%
% Inputs
% ——————
% N – Integer value for the size of the square.
%
% Inputs
% ——————
% M – Your Latin Square
%
% Other functions
% ——————-
% RANDPERM(n) is a random permutation of the integers from 1 to n.
% For example, RANDPERM(6) might be [2 4 5 6 1 3].
%
% CUMSUM(X) is a vector containing the cumulative sum of the elements of X.
% Example: If X = [0 1 2
% 3 4 5]
% then cumsum(X,1) is [0 1 2 and cumsum(X,2) is [0 1 3
% 3 5 7] 3 7 12]
% email: richard [ a t ] richard-craig.co.uk
% Download if too lazy to copy and paste
function [M] = latsq(N)
M = [randperm(N); ones(N-1,N)] ; % Generate Square
M = rem(cumsum(M)-1,N) + 1 ; % Add one due to base zero
Update Simulink variables from MATLAB GUI
This example is designed to demonstrate how to control variables within a SIMULINK model before starting the simulation or in real time during the simulation. Although the same commands can be used from the MATLAB command window, I wanted to use a Graphical User Interface (GUIs) as it would co-ordinate with other applications.
Because the GUI sets parameters and runs the simulation, the 'EEG_BERT_FACE.mdl' model must be open when the GUI is displayed.
The purpose of the subfunction is to:
- Determine if the model is open (find_system).
- Open the block diagram for the model and the subsystem where the parameters are being set, if not open already (open_system).
- Change the size of the controller Gain block so it can display the gain value (set_param).
- Bring the GUI forward so it is displayed on top of the Simulink diagrams (figure).
- Set the block parameters to match the current settings in the GUI.
Here is the code for the model_open subfunction:
function SIMULINK_model_open(handles)if isempty(find_system(‘Name’,'EEG_BERT_FACE’)),% Open the model file ‘EEG_BERT_FACE.mdl’
open_system(‘EEG_BERT_FACE’);% Variables updated from the MATLAB GUI
set_param(‘EEG_BERT_FACE/To File’,'Filename’,handles.sfilename); %Block Property Variable%Gain Parameters
set_param(‘EEG_BERT_FACE/gStimulus’,'Gain’,'0′);
set_param(‘EEG_BERT_FACE/gFaceID’,'Gain’,'0′);
set_param(‘EEG_BERT_FACE/gFaceCount’,'Gain’,'0′);
set_param(‘EEG_BERT_FACE/gStepNumber’,'Gain’,'0′);
set_param(‘EEG_BERT_FACE/gNumberOfRuns’,'Gain’,'1′);
set_param(‘EEG_BERT_FACE/gVarDelay’,'Gain’,num2str(handles.time_addition));end
function SIMULINK_model_update(handles)
%Gain Parameters
set_param(‘EEG_BERT_FACE/gStimulus’,'Gain’,'0′);
set_param(‘EEG_BERT_FACE/gFaceID’,'Gain’,num2str(handles.fID));
set_param(‘EEG_BERT_FACE/gFaceCount’,'Gain’,num2str(handles.iFace));
set_param(‘EEG_BERT_FACE/gStepNumber’,'Gain’,num2str(handles.iStep));
set_param(‘EEG_BERT_FACE/gNumberOfRuns’,'Gain’,num2str(handles.iRuns));
set_param(‘EEG_BERT_FACE/gVarDelay’,'Gain’,num2str(handles.time_addition));function SIMULINK_model_close(handles)
set_param(‘EEG_BERT_FACE’,'SimulationCommand’,'pause’);
set_param(‘EEG_BERT_FACE’,'SimulationCommand’,’stop’);
save_system(‘EEG_BERT_FACE’);
close_system(‘EEG_BERT_FACE’);
Matlab Quadratic Programming Optimisation Problem
Problem
Find minimum of x^2 + 4y^2 -3xy -3x -7y
Subject to 0<x<7 0<y<7
Change constraints till you hit both
Matlab Solution
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Programme : EngD Maths for Systems % Date : 2011-06-01 % Session : Optimisation % Exercise : Material Blending % By : Richard Craig % % Description: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% quadprog4.m %Find minimum of x^2 + 4y^2 -3xy -3x -7y %Subject to 0<x<7 0<y<7 clc; clear; %% Set up function for optimization % H will give expression of form: % h11.x1^2 +h12.x1.x2 +h21.x2.x1 +h22.x2^2 % but programme forces symmetric Hessian: h12=h21 etc., % so might as well make it symmetric now. % from the eq we can see H = [x^2 + 4y^2 -3xy] f = [ -3x -7y] H = [2 -3; -3 8]; %H = [x^2 + 4y^2 -3xy] % f will give inner product f.x f = [-3; -7]; % f = [ -3x -7y] %% Constraints %x = quadprog(H,f,A,b,Aeq,beq) solves the preceding problem while %additionally satisfying the equality constraints Aeq*x = beq. %If no inequalities exist, set A = [] and b = []. A = [];b = []; %lower bounds on x: lb = zeros(2,1); %upper bound on x: ub = [16 7]; %[7 7]; %Subject to 0<x<7 0<y<7 %% View Function % make a "meshgrid" to cover allowed ranges of the variables. u=linspace(lb(1),ub(1),11); v=linspace(lb(2),ub(2),11); [X, Y]=meshgrid(u,v); % put a value to each point-pair of the grid: Z=0.5*(H(1,1)*X.^2 + H(2,2)*Y.^2 + 2*H(1,2).*X.*Y) + f(1).*X + f(2).*Y; %plot the surface with some colour and a contour plot underneath: h = figure(1); surfc(X,Y,Z) saveas(h,'QuadSurface.jpg'); %% Minimize using 'quadprog' % Call for quadratic programming method: [x,fval] = quadprog(H,f,A,b,[],[],lb,ub)
Matlab Shortest Path Optimisation Problem
Problem
Find the quickest route to visit friend?
Matlab Solution
This program generates a matrix representing the connections between each node.
Values for the NodeID(Source), NodeID(Destination) and weight of the connection (ie Distance) are given. For example from the ‘Home’ node (which I have given the NodeID =1), we see two routes (links) ; one of ‘distance=14′ and one of ‘distance=1′.
The first connection is labelled from the ‘Home’ NodeID=1 to a new NodeID=2 and is given the weighting or ‘distance’=14. The second route from the ‘Home’ NodeID=1 therefore connects to a new NodeID=3 and is given the weight or ‘distance’=1. From what I have defined as NodeID=2 then has two more routes from the node with weights (distances) or 15 and 8. This pattern of NodeID allocation and describing the output routes to other nodes continues until you have described the system.
The matrix is predefined from the system above; NodeSource, NodeDestination, Distance; 1,2,14; 1,3,1; 2,7,15; 2,5,8;
The shortest route through the node network is found using the Bioinformatics Toolbox™ function graphshortestpath that provides the path and overall connection value.
Matlab Code
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Programme : Maths for Systems % Date : 2011-05-11 % Session : Optimisation % Exercise : SHORTEST PATH PROBLEM % By : Richard Craig % % Description: % This program generates a matrix representing connections between nodes. % Values for the NodeID(Source), NodeID(Destination) and weight of the % connection (ie Distance) are given. The shortest route through the node % network is found using the Bioinformatics Toolbox™ function % graphshortestpath that provides the path and overall connection value. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Close figures and clear all previous variables clc;close;clear; %% Create a node matrix [NodeSource,NodeDestination,ConnectionWeight] mNodes = [... 1,2,14; 1,3,1; 2,7,15; 2,5,8; 3,4,7; 3,6,10; 4,8,20; 5,7,10; 5,6,10; 6,9,15; 7,10,13; 7,9,14; 8,11,7; 9,13,12; 9,11,14; 10,14,15; 10,12,8; 11,15,16; 11,16,14; 12,14,10; 12,13,6; 13,15,7; 14,19,14; 15,17,17; 15,18,25; 16,18,5; 17,19,6; 17,18,7; 18,19,8; 19,20,2; ]; %% Generate a matrix % N-by-N sparse matrix that represents a graph. Nonzero entries in matrix G % represent the weights of the edges. % SizeX = SizeY = Number of Nodes % nNet = sparse(nSource,nDestination,nWeight,SizeX,SizeY); nNet = sparse(mNodes(:,1),mNodes(:,2),mNodes(:,3),20,20); %% Find the shortest path via a MATLAB function % Using the Bioinformatics Toolbox™ function graphshortestpath the shortest % path between [S = Starting Node] and [T = Final Node] can be found using %[dist, path, pred] = graphshortestpath(G, S, T) [dist, path, pred] = graphshortestpath(nNet,1,20); %% Plot the Result % Create the biograph object bnNet = biograph(nNet,[],'ShowWeights','on'); % Create a graphics handle from the biograph object h = view(bnNet); % Mark the nodes and edges of the shortest path by colouring them red and % increasing the line width. set(h.Nodes(path),'Color',[1 0.5 0.5]); % Update Nodes(on the path) with a colour edges = getedgesbynodeid(h,get(h.Nodes(path),'ID'));%Get edge nodesID set(edges,'LineColor',[1 0 0]); % Change line colour set(edges,'LineWidth',1.5); % Change line with %% Display the Results clc;%Clear the cmd window disp(['Shortest path is via nodes ' num2str(path)]); disp(['Distance of the shortest path is ' num2str(dist)]);
MATLAB updates Access database via SQL
Matlab is able to store variables in files and can import external information from excel and access, but sometimes you want to keep the information in Access and only do some processing in MATLAB. Here is some code to use Structured Query Language (SQL) to update an Access database from within MATLAB;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% File : DatabaseConnection.m
% Date : 2011-07-04
% Revision : 1.0
% By : Richard Craig
%
% Description:
% This file imports external information from an Access database into
% Matlab.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Clear all variables, close all windows
clear all;close all;clc;
%% % Taken from http://www.mathworks.com/help/toolbox/database/ug/database.html
% Specify the location of the database on disk.
dbpath = ['C:\Users\Richard\Desktop\Database.mdb'];
% Create the connection URL.
conurl = ['jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};' ...
'DBQ=' dbpath];
% Connect to the database.
conn = database('','','','sun.jdbc.odbc.JdbcOdbcDriver', conurl);
if isconnection(conn)
display('Connected');
% Fetch data from the database.
%Import table as-is
%e = exec(conn,'SELECT * FROM tbl_table'); %Run an SQL statement
% Apply a filter to results
e = exec(conn,'SELECT * FROM tbl_table WHERE [Type] like ''Academic (Civil)'' '); %Run an SQL statement
% Run SQL statement
e = fetch(e);
data = e.Data; % Transfer data to workspace variable
display('Information imported');
[rows cols] = size(data);
for i=1:rows
% Informaton will be stored as a cell so will need converstions to
% string (char(var)) and then numeric (str2num(char(var))
% Assign to variables
ID = cell2mat(data(i,1));%Numeric
Name = char(data(i,2));%String
Url = char(data(i,3));%String
Url = strrep(Url,'#',''); %Remove errors in string
data(i,3) = cellstr(Url);% Reassign string to cell
% but that only updates the variable not the actual table in our
% database.
% We need to use an SQL statement;
s =['UPDATE [URL] FROM tbl_table WHERE [ID] =' num2str(ID)];
%sql = exec(conn,s);%execute statement
%BE SURE the sql statement works as you want on the local data
%variable and BACK UP your information before running ANY SQL
%statement for the first time.
%Display Result
disp([num2str(ID) ' - ' Name ' ' Url ]);
end%i=1:rows
end %isconnection(conn)
%% Close the connection.
close(conn);
Matlab Material Blending Optimisation Problem
Problem
Various source alloys, A,B,C,D,E are available with different proportions of elemental metals and costs. Need to make final blend with 30% Lead, 20% Zinc and 50% Tin at lowest cost.
| A | B | C | D | E | Req. | |
| Lead | 10 | 10 | 40 | 60 | 30 | 30 |
| Zinc | 10 | 30 | 50 | 30 | 30 | 20 |
| Tin | 80 | 60 | 10 | 10 | 40 | 50 |
| Cost | 8. | 9. | 11. | 13 | 17 |
Adapted from Ref 2, Bhatti, p424
Matlab code
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Programme : EngD Maths for Systems % Date : 2011-06-01 % Session : Optimisation % Exercise : Material Blending % By : Richard Craig % Description: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Clear previous variables clc; clear all; %% Blending Problem. % A B C D E Req % Lead 10 10 40 60 30 30 % Zinc 10 30 50 30 30 20 % Tin 80 60 10 10 40 50 % Cost 8.0 9.0 11.0 13.0 17.0 % % % Various source alloys, A,B,C,D,E are available with different proportions % of elemental metals and costs. M = [10 10 40 60 30 10 30 50 30 30 80 60 10 10 40]; % Final solution material boundary b = [30; 20; 50]; % Define a lower bound and an upper bound for each variable. lb = zeros(5,1); % Can't have minus material ub = ones(5,1); % Can't have more than 100% of one material % define the objective function for Minimize(f.x) f = [8.0; 9.0; 11.0; 13.0; 17.0]; %Price per unit %% call the linear programming operation [x,fval,exitflag,output,lambda] = linprog(f,[],[],M,b,lb,ub); % lambda.ineqlin % lambda.eqlin % lambda.upper % lambda.lower %% ANSWER x % Final Blend of materials id given in the proportions; % x = 0.5714 % 0.0000 % 0.0714 % 0.3571 % 0.0000
Matlab Open Box Optimisation Problem
Problem
Builder wants open boxes, carry 1200 cu ft of stuff; walls, ends, base different construction, different (lifetime) costs. Wants to minimize (lifetime) cost.
Problem is Min{48bh+30bl+44hl} subject to bhl=1200.
Find: b=breadth, l=length, h=height.
Matlab Solution
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Programme : EngD Maths for Systems
% Date : 2011-06-01
% Session : Optimisation
% Exercise : OPEN BOX PROBLEM
% By : Richard Craig
%
% Description:
% Builder wants open boxes, carry 1200 cu ft of stuff;
% walls, ends, base different construction, different (lifetime) costs.
% Wants to minimize (lifetime) cost.
% Problem is Min{48bh+30bl+44hl} subject to the constraint that bhl=1200.
% Find: b=breadth, l=length, h=height.
%
% Adapted from Ref 2, Bhatti, “Practical Optimization Methods”.
h = 12; % Height
b = 12; % Breadth
l = 12; % Length
x0 = [h; b; l]
%Cost function (Min{48bh+30bl+44hl}):
fun = @(x) (48*x(1)*x(2))+(30*x(2)*x(3))+(44*x(1)*x(3));
%Constraint
C = 1200;
lb =zeros(1,3); ub = [C,C,C];
%Constrain volume
%By using @nonlcon4 function in separate m file called nlcon4.m:
% function [c,ceq] = nonlcon4(x)
% %Input variable x = [H,B,L]
% ceq = 1200-x(1)*x(2)*x(3);
% c = [];
% end
%Minimization variables A,b,Aeq,beq,
%% Find minimum of constrained nonlinear multivariable function
%x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,@nonlcon4)
x = fmincon(fun,x0,[],[],[],[],lb,ub,@nonlcon4)
% x =
% 7.9967
% 11.7285
% 12.7947
y = fun(x) % y = 1.3506e+004
%% Extra
% Vary capacity in nonlcon4 to 1210
C = 1210;
ub = [C,C,C]; % new upper limits
x = fmincon(fun,x0,[],[],[],[],lb,ub,@nonlcon4) %Re-eval
% x =
%
% 8.0188
% 11.7610
% 12.8301
y = fun(x) % y = 1.3581e+004
Java Hello World
It’s finally time I got around to learning java. I’ve spent most of the past few years using Matlab and writing C or vb applications.
Here are some easy lead in and hello world examples for java.
import javax.swing.JOptionPane;public class HelloWorldGUI {
public static void main(String[] args) {
System.out.print("Hello World");
JOptionPane.showMessageDialog( null, "Hello World!" );
}
}This is a nice easy into to java programming as the universal ‘Hello World’ application helps demonstrate functionality with a minimum of code.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class HelloWorldGUI2 {
private static class HelloWorldDisplay extends JPanel {
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawString( “Hello World!”, 20, 30 );
}
}
private static class ButtonHandler implements ActionListener {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
}
public static void main(String[] args) {
HelloWorldDisplay displayPanel = new HelloWorldDisplay();
JButton okButton = new JButton(“OK”);
ButtonHandler listener = new ButtonHandler();
okButton.addActionListener(listener);
JPanel content = new JPanel();
content.setLayout(new BorderLayout());
content.add(displayPanel, BorderLayout.CENTER);
content.add(okButton, BorderLayout.SOUTH);
JFrame window = new JFrame(“Hello World”);
window.setContentPane(content);
window.setSize(250,100);
window.setLocation(100,100);
window.setVisible(true);
}
}
Installing JOGL and configuring for Windows and Eclipse
After a headache trying to find the right files and the standard ‘playing about’, I’ve finally got my OpenGl ‘Hello World’ example up and running. Before I forget, I thought I’d post my installation list as others seem to be getting dated.
I’ve modified the instructions from Matt Kindy http://kindy.net/jogl_setup.txt
DOWNLOAD ECLIPSE
1. Download Eclipse from the
http://www.eclipse.org/downloads/
I’m currently using ‘Eclipse for RCP and RAP Developers, 189 MB windows 32 Bit‘
2. There is no installer (executable program) used to install Eclipse. Just unzipping to a directory in an appropriate location on your hard disk (e.g. ‘C:\eclipse\‘). It is very strongly recommended that you locate the eclipse directory at the root of your computer hard drive or on a directory path with no spaces in its name (e.g. ‘C:\software\eclipse\‘). Eclipse does not write entries to the Windows registry so you can simply delete (or move) the directory, installed files, shortcuts, and/or the workspace: there is no executable uninstaller either so shift+Delete anytime.
3. Run Eclipse by running ‘C:\software\eclipse.exe‘ executable
DOWNLOAD JOGL
1. Download JOGL from the JogAmp.org site:
http://jogamp.org/deployment/webstart/archive/
At the bottom you’ll find jogl-v2.0-rc2.zip 03-Mar-2011 03:23 18M
Download and extract the ZIP file into a folder.
COPYING FILES
2. Create a folder in a convenient place to contain the necessary JOGL .jar files
e.g ‘C:\software\java\jogl\2.0\‘
3. Copy the .jar files from the folder in step 1 to the folder created in step 2.
============================
OPTIONS
Now this is where the given example and my way differs.
I will add my way at the end, so feel free to follow this way or jump to my way at the end ![]()
============================
4. Copy these DLL files to the Java Runtime Environment bin folder (e.g. ‘C:\Program Files\Java\jre6\bin‘):
gluegen-rt.dll
jogl.dll
jogl_awt.dll
jogl_cg.dll
SETTING ENVIRONMENT VARIABLES
5. Open the Windows environment variable window:
- Right-click My computer, choose Properties
- In Vista, choose “Advanced System Settings”;
In XP, choose the Advanced tab
- Click the “Environment Variables” button
- Under “System Variables” you will edit the following variables:
6. CLASSPATH
Add to the end of CLASSPATH the path to the JOGL .jar files folder (created in step 2)
- be sure the added path string is separated from the original string by a semicolon (;)
7. java.library.path
Create this environment variable with the path to the JRE bin folder (see step 4)
USING IN ECLIPSE
8. When you make a project in Eclipse, you will need to add the JOGL .jar files
to the project. To do so:
- right-click the project name and choose properties
- Choose “Java Build Path” in the left pane
- Choose the “Libraries” tab
- Click “Add External JARs”
- Browse to the folder from step 2. Add each of the JOGL .jar files to the project
IMPORTING THE JOGL LIBRARIES IN JAVA
9. To use in your Java program, add these lines to the appropriate class files:
import javax.media.opengl.*;
import com.sun.opengl.util.*;
import javax.media.opengl.glu.*;
Specifically, you’ll need these classes:
javax.media.opengl.GL
com.sun.opengl.util.GLUT
com.sun.opengl.util.Animator\
among others.
============================
My Way from Step 4.
============================
Eclipse
4. Start Eclipse and create a new java project File > New > java project
You can call the project ‘HelloWorld’
Make sure the execution environment is ‘JavaSE-1.6′
Click NEXT
5. Select the Libraries tab and click ‘Add Library’
Select ‘User Library’ as we’re going to create our own Jogl library
Select ‘User Libraries’ as the list should be empty
Now click ‘New’ and call the library ‘Jogl2.0′ and click ‘ok’
Click on the new ‘Jogl2.0′ library
Select ‘Add JARs’ and move to your jogl directory (type C:\software\java\jogl\2.0\lib into the filename and click open)
Add files to library
nativewindow.all.jar
newt.all.jar
gluegen-rt.jar
jogl.all.jar
Optional
You might want to expand (click on the plus sign) the library and attached files
then click on ‘Native library location’ and click ‘Edit’
then enter the path to your jogl lib directory (‘C:\software\java\jogl\2.0\lib‘)
repeat for all attached files
6. Now you should have a user library to add called ‘jogl2.0′ (or whatever you called yours)
Whenever you start a new project you’ll be able to right click on the project icon
Select Properties
select Java build path
select Add library > User library > Jogl2.0
JoGL ‘Hello World’ Example
Now you’ve got Eclipse and Jogl installed, you’ll probably want a great JoGL ‘Hello World’ example to try >>

