Skip to content

Examples

Alex Henderson edited this page Feb 7, 2024 · 1 revision

Home > Example usage

Example usage

See also the pccva_example.m file in the Data folder.

Example 1

Assuming you have a .spc file in this location: C:\mydata\myfile.spc

filename = 'C:\mydata\myfile.spc';
myfile = ChiSPCFile.open(filename);
myfile.plot;

Example 2

Assuming you have multiple SPC files in the same folder

myfiles = ChiSPCFile.open();

A dialog box will open allowing you to navigate to the location of the files.
Select as many as required. Use the shift and/or ctrl keys to assist you

myfiles.plot;			% overlay of the spectra
myfiles.plot('mean');		% mean of the spectra
	
myfiles.history.log		% list of filenames

Perform principal components analysis

pca_result = myfiles.pca;
pca_result.plotloadings(1);	% the loading on pc 1
pca_result.plotloadings(2);	% the loading on pc 2
pca_result.plotscores(1,2);	% scores plot of pc 2 versus pc 1

Example 3

Vector normalisation

myfiles = ChiSPCFile.open();

A dialog box will open allowing you to navigate to the location of the files. Select as many as required.

Both the following lines do the same thing, producing a copy of the data that has been vector normalised.

myfiles_vn = myfiles.vectornorm;
myfiles_vn = vectornorm(myfiles);

The following line vector normalises the data in situ and does not produce a copy.
Note the original variable is modified (but nothing changes the files on disc).

myfiles.vectornorm;

Example 4

Assuming there are 8 SPC files and you have some a priori knowledge. Assume there are three classes of data alpha, beta and gamma and the files are in the order: beta, gamma, gamma, beta, beta, beta, alpha, alpha

spectra = ChiSPCFile.open();	% select the 8 files

apriori = ChiClassMembership('myinfo','beta',1, 'gamma',2, 'beta',3, 'alpha',2);
spectra.classmembership = apriori;

spectra.plot			% overlay of all spectra
spectra.plot('grouped')		% overlay of all spectra with the same classes in the same colour
spectra.plot('mean')		% mean of the 8 spectra
spectra.plot('mean','grouped')	% mean of each of the classes 

pca_result = spectra.pca;
pca_result.plotscores(1,2);	% scores plot of pcs 1 and 2 labelled according to the class structure

Example 5

Assuming you have an Agilent FTIR image tile in this location: C:\mydata\myfile.seq

filename = 'C:\mydata\myfile.seq';
myimage = ChiAgilentFile.open(filename);

myimage.display;	% total intensity image
myimage.plot('mean');	% the average spectrum across all pixels in the image
myimage.plot('std'); 	% the average spectrum, with the standard deviation shaded, across all pixels in the image

To perform principal components analysis on the image

pca_result = myimage.pca;
pca_result.imagepc(1);			% scores image of principal component 1
pca_result.plotloading(1);		% loading on pc 1
pca_result.plotexplainedvariance;	% percentage explained variance
pca_result.plotcumexplainedvariance;	% cumulative percentage explained variance, with a line at 95%

Example 6

Read any single file without specifying the format. If you don't specify a filename, a dialog box will appear with all readable files highlighted.

filename = 'C:\mydata\myfile.seq';
myimage = ChiFile(filename);

or

myimage = ChiFile(); % Then navigate to the appropriate file.  
Clone this wiki locally