View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from

4.6 | 20 ratings Rate this file 53 Downloads (last 30 days) File Size: 14.9 KB File ID: #22114 Version: 1.11




15 Nov 2008 (Updated )

a version of abfload which is capable of reading abf 2.0 files

| Watch this File

File Information

I have taken abfload, and am in the process of updating it for abf 2.0 file formats... so far I have gap free recording working, but haven't finished the other modes.. though they shouldn't be too hard. I would welcome people auditing the code.. i have attached in comments the information from the C file from axon I used to help decode the header information. You can get the C code yourself here

the original abfload can be found here

This is still a work in progress.

Harold Hentschke, the original author of abfload fixed a couple bugs and cleaned up the code, and i am updating this version to include his changes which are:
- fixed a bug regarding the fADCSampleInterval being incorrectly set
- restructured the code so it's easier to see which portions deal with which ABF version
- incorporated all accessory functions as subfunctions
- changed the number type of 'fFileVersionNumber' back to floating point
- updated the copyright note
Further updates from Forrest Collman:
-added support for reading in tags, both in abf 1.0 and 2.0 format
-fixed bug associated with reading in files created in axoscope.
-fixed a bug with my tag support, i had assumed there were tags to be read, should work now on either.

---updates from Harold (06/2011)
bug fixes:

- in the precursor version (abfload) there was a potential problem in the gap-free reading mode: in exceedingly rare cases an error resulted when reading data, namely when division of the number of points by 'chunkPtsPerChan' (see input variable 'chunk') left no remainder

- abfload would only recognize abf files recorded from some of the Axon/MolDev programs (clampex & axoscope). This was due to an incomplete list of programs listed in variable 'progString'. abfload should now read data produced by clampex, clampfit, axoscope and patchxpress

- changes to the tag section which hopefully cover all of the reported problems

other changes:

- some restructuring of code for better oversight and/or in conjunction with bug fixes, modified comments

- data in 'high-speed oscilloscope' mode can now be read (in addition to the two other waveform fixed-length modes)

- right below H1 there is a 'PROBLEM CASE REPORTS' paragraph in which very specific, as yet unresolved problems with abfload (and recording abf files in general) are listed, which may help resolve related issues


Abfload inspired this file.

This file inspired A Panalysis, Cengique/Pandora Matlab, Peaker Analysis Toolbox, and Load Vclamp Abf.

MATLAB release MATLAB 7.6 (R2008a)
Other requirements Not sure it works on PCs, developed on a mac reading abf files made on a PC.
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (29)
13 Jul 2016 SKMEA6

SKMEA6 (view profile)

Cengiz: Thanks a lot for your reply. I did some math and found out, that the numbers I get in h.tags have to be multiplied by the sample interval (50 ┬Ás in my case) to yield the time in seconds. I think somewhere it was written that it would directly give the value in seconds. Not sure whether this behavior is intended?

Comment only
30 Jun 2016 mtross

mtross (view profile)

29 Jun 2016 Cengiz Gunay

SKMEA6: Sometimes the sampling rate may be annotated wrong in the file so just make sure that they are correct.

Comment only
24 Jun 2016 SKMEA6

SKMEA6 (view profile)

Thank you very much for putting this together.
However, I do not seem to get correct time stamps for the tags. I have a gap-free recording of approx. 30s with 14 tags distributed +/- evenly along the file. But I just get times below 1s out of the structure.

e.g. Tag 11 is at 22.477s in ClampFit, but:

>> h.tags(11).timeSinceRecStart

ans =


I am new to MATLAB. Am I missing or confusing something?

Thanks a lot in advance,

25 Mar 2016 Marjan R

I am using this m file in order to import the abf file from Clamfit(version Yesterday by "accident" I was comparing the abf file on Clampfit, and also MATLAB. I realized after importing the abf file into MATLAB, the currents are shifted by -20 pA. For example, by looking at the Clampfit I can see the rheobase current is around 42 pA, while MATLAB gives me the value of 21 pA.

Is this version of abfload adoptable to clampfit version Why Im not getting the same number as the real data file in Clampfit?!If I was not checking my file accidentally on Clampfit there was no way for me to fidn out abfload.m is shifting my input currents by ~ -20 pA... This is very annoying. What should I do?!

Comment only
08 Feb 2016 Saray Soldado Magraner

Dear Forrest
First of all thanks a lot for this extremely useful script :)
I have a question similar to Scott's one. Is the waveform recorded somewhere? I would like to plot an FI courve, from data recorded in current clamp. Maybe I have missed it but I did not see any variable where the values of the current employed are displayed.
Let me know if this is not the case.
Thanks a lot,

01 Apr 2015 Cengiz Gunay

If you're getting the error

** abfload
Index exceeds matrix dimensions.

Error in abfload>pvpmod (line 1060)
assignin('caller', x{i}, x{i+1});

Error in abfload (line 145)

In Matlab version 2014a, you can fix this by changing line 140 to:

if nargin==2 && ischar(varargin{1}{1}) && strcmp('info',varargin{1})

The only change is in the the ischar check, addressing varargin{1}{1} instead of varargin{1}. It's strange, but it works.

21 Aug 2014 Thijs

Thijs (view profile)

17 Jul 2014 Jeffrey Johnson

Very useful, thank you!

One suggestion - I had some trouble with rounding errors in the calculation of the start point. This appears ultimately to have been due to a badly-written header value for h.fADCSampleInterval (MCDataTool's problem, not yours!) but I was able to partially solve the problem by changing lines 674/683 from FLOOR commands to ROUND commands. I don't understand the use of FLOOR here, since the values on these lines ought to come out integers (subject to rounding error)...we don't want to FLOOR an index value of 4.99999999 to 4!

Also, line 676 appears to be useless. Due to the FLOOR (or ROUND) operation on 674, STARTPT is already an integer. 676 takes the FLOOR of STARTPT*X/X, which certainly won't fix a rounding error but could introduce one. I have commented 676 out to no detriment.

As a side note, if anybody is using MCDataTool to export to .abf, you may have a problem with the value of h.fADCSampleInterval as written to the header. (This is not the fault of ABFLOAD.) If you believe you may be getting frame shifts when reading an .abf written by MCDataTool, feel free to contact me via the email listed in my profile.

18 Mar 2014 Blake Richards

Worked perfectly for me using ABF v2 files with both episodic and gap-free data! Thank you!!!!

26 Jul 2013 James Hounshell

13 Jun 2013 Forrest Collman

hi scott,

i'm not sure actually. i sent you an email to your yahoo address, if you send me a sample i can take a look.


Comment only
13 Jun 2013 Scott

Scott (view profile)

Sorry if I overlooked something obvious, but I was wondering if there is a way to extract the waveform data (i.e. the command waveform for vclamp experiments) for Abf v2 files. I am (unfortunately) working with both v1 and v2 files. I found that readabf extracts the command waveform info for abf<2 but when I try to use it on abf=2, I get a "maximum variable exceeded" error.
Any advice on how to best extract the command waveform information would be greatly appreciated!

11 Jul 2012 Jonas

Jonas (view profile)


I'm using abf2load for plotting of IV curves from episodic traces.

I'm not very experienced in Matlab. Is there any possibility to extract the clampex comment (which you can manually enter after a each recording) in with abf2load?
I was trying to find it in the code but was unsuccessful so far. Would be nice if someone could give me some advice.

Thanks in advance,

Comment only
29 Jun 2012 wjg

wjg (view profile)

Another bug + fix. If you request a subset of channels, you get them in the order listed in the 'channels' argument. However, if you request all channels, they always are returned in the same order as the file, even if the order given in 'channels' is different. The fix is to change line 674 from:

elseif length(chInd)/h.nADCNumChannels<1


elseif length(chInd)/h.nADCNumChannels<1 || any(chInd ~= 1:h.nADCNumChannels)

Comment only
06 Jun 2012 Matthew

@Ryan and anyone else having the empty goodstart problem:

Look at lines 270 through 275. The name of the program that saved the ABF file is part of the file format. If you saved yours in another program, for instance Clampfit, changing 'axoscope' to the name of the program should work (or, for slightly more robustness, adding a second isempty() check). It solved the problem for me, although it's still a messy hack (as the comments in 270 and 272 do, to be fair, point out).

Comment only
08 Jun 2011 Ryan

Ryan (view profile)

I have the same problems with the tag section, which I have to comment out. Once I do that, the program works about 80% of the time as opposed to about 30% of the time. I also have issues with the following error:

??? Attempted to access goodstart(1); index out of bounds because numel(goodstart)=0.

Error in ==> abfload at 277

Error in ==> Converter at 63

09 Feb 2011 Arthur

Arthur (view profile)

Forrest, I ran into a problem with abf files containing tags. When I try to load them I get the following error:

??? The following error occurred converting from struct to double:
Error using ==> double
Conversion to double from struct is not possible.

Error in ==> abfload at 327

The problem seems to be in the line just before (line 325):


This creates an empty double array, but output of the following loop is a struct. Simply commenting line 325 solved the problem for me.

Thanks again for an otherwise great function.

Comment only
29 Oct 2010 Cengiz Gunay

Apologies.. The file I was trying to load seem to be corrupt and couldn't be loaded by pClamp 10, either. So please ignore the previous post. The correct files can be read by abf2load. Thanks!

27 Oct 2010 Cengiz Gunay

I am getting this error with some ABF2 files from pClamp10:

>> Kslow1_vc = abf2voltage_clamp([ Kfastslow_datadir '008/09821026.abf' ]);
** abf2load
opening ~/prinzlab/Logy/Data Compilation/Potassium Data/Subtracted/008/09821026.abf..
{??? Index exceeds matrix dimensions.

Error in ==> abf2load at 291
h.recChNames=strvcat(h.recChNames, Strings{ADCsec(i).lADCChannelNameIndex});
291 h.recChNames=strvcat(h.recChNames, Strings{ADCsec(i).lADCChannelNameIndex});
K>> ADCsec(i).lADCChannelNameIndex

ans =


There are only about 7000 Strings, so this is way out of bounds. I also tried the python version of abf2load that is part of Neo, but that chokes on these files, too. I can send a copy of the file if you can take a look at it.

Thanks for the otherwise very useful utility!

(molecular devices developer page link is broken now. Is there a way to get to that code?)

18 Aug 2010 Andrius Gaigalas

I can read gap free abf files only if statements 326-329 are comments. This problem was seen before and I thought it was fixed. I have MatLab R2009 student edition runing on MS Vista.

28 Jul 2010 Rune W Berg

09 Jul 2010 Arthur

Arthur (view profile)

works great!

23 Mar 2010 Julie Haas

Thanks so much! Works great on my episodic data on a PC.

13 Aug 2009 Peter

Peter (view profile)

Works with my episodic stimulation-recording data. Thanks for sharing the code!

29 Jul 2009 Olivier

Olivier (view profile)

28 Jul 2009 Forrest Collman

I have fixed the error that was causing JoAnna's problem

Comment only
21 Jul 2009 JoAnna

JoAnna (view profile)

I commented out line 329, and importing abf v2.0 files seems to work now.

21 Jul 2009 JoAnna

JoAnna (view profile)

Currently, it is unable to run. It appears to have errors in the "tag" support that was recently added. Thus far I have had errors in lines 321 and 329.

19 Nov 2008 1.1

edit) i have fixed one bug.. an indexing error
i think there are problems with the scale factors,
i have had success loading episodic stimulation

25 Nov 2008 1.2

Made the reading of selective channels by name work correctly.

18 Dec 2008 1.3

typo in the description

13 Jan 2009 1.4

included Harold's changes to code, consolidated functions into one m file

15 Jul 2009 1.5

add tag support, also axoscope

21 Jul 2009 1.6

fixed bug when there are no tags

28 Jul 2009 1.7

fixed another tag bug

02 Jul 2011 1.8

Harald fixed some abf 1.0 issues

04 Jul 2011 1.9

added description of most recent changes

16 Aug 2012 1.10

Various bug fixes, reinstating lost updates due to fileexchange bug.

26 Jul 2013 1.11

Fixed bug when channel has no units.

Contact us