File Exchange

image thumbnail

Adaptive Neuro-Fuzzy Inference Systems (ANFIS) Library for Simulink

version 1.30 (759 KB) by Ilias Konsoulas
This Simulink library contains six ANFIS/CANFIS system variations.


Updated 01 May 2015

View License

This library is for those who want to use the ANFIS/CANFIS system in the Simulink environment. Each model is implemented for training and operation in a sample-by-sample, on-line mode. For details see the included release notes. The main reference used to develop all the ANFIS/CANFIS models is:
Neuro-Fuzzy and Soft Computing: A Computational Approach to Learning and Machine Intelligence, Jyh-Shing Roger Jang, Chuen-Tsai Sun, Eiji Mizutani. Prentice Hall, Sept. 1997.

Comments and Ratings (72)

Arun Kammath

Hi lias, I have installed the toolbox butimanot able to find it inside simulink. please guide me through :)

@ Carolin Wendelborn: Please use my email to submit long/multiple questions. CANFIS/ANFIS with 100 inputs more likely won't work even if you had the required computational power.

As a beginner in computational intelligence methodologies, I want to thank you for the detailed documentation of your work.

I am trying to implement the CANFIS Scatter system in order to develop a MIMO controller. As I do not have optimal input-output pairs for training, I implemented a Control Law, calculating the error e. This is similar to the ball & beam example, just that my error value derives from "answer of the system" minus the "desired answer" and not from the difference between desired and actual control command.

Unfortunately I get an error while executing the CANFIS S-function "Error in '(Scatter)/CANFIS' while executing MATLAB S-function 'canfisim_scatter', flag = 3 (output), at time 1.805. Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To perform elementwise multiplication, use '.*'
Any idea what could cause this?

Another question: How do you usually chose the setting parameters like the learning rate? Is this a trial and error process in most of the cases?

For a future project, I plan to build a controller with over 100 input variables and 40 output variables. Do you see any problem in using CANFIS-scatter for so many variables?

Many thanks already in advance, I would really appreciate any input to these questions!

Dear Ilias,

I have installed the toolbox. I am not able to run the demos as the mat file is not provided with the same. Even when I double clicked to load Lorenz attractor data it says the data does not exist. A quick help would be greatly appreciated.

@ Stav Bar-Sheshet. P is the inverse of the input signals autocorrelation matrix and ThetaL4 are the linear consequent parameters. ThetaL4 is adjusted by RLS by use of recurcive estimation of P. Consult any good book on RLS algorithm to understand their role. Regarding the ANFIS net, ThetaL4(:,k) contains the alphas [a1,k a2,k ... aNinputs,k a0,k] associated with the k-th fuzzy rule. See equation (8) of the manual (Layer 4 function). The dimension of P is (NumInVars+1)*NumRules X (NumInVars+1)*NumRules). The dimension of ThetaL4 is (NumInVars+1)*NumRules X 1 for ANFIS (a vector) and (NumInVars+1)*NumRules X NumOutVars for CANFIS (a matrix). The derivatives are simply the derivatives of means, sigmas and b's calculated by backpropagation at the previous time step. They need to be stored somewhere as well in ordert to be used for Backprop with momentum term (alpha). dThetaL4 is supposed to accommodate the derivatives of ThetaL4 in afuture implementation, they play no role in this one.

Hi Ilias,
In the Xt vector, I understand that mean, sigma and b are the parameters for the Bell MF.
Can you please specify the rest? P, ThetaL4, and the derivatives?
My intention is to track overtraining, so if you have other ideas it will be great to hear.

@ Amirreza. Thank you very much for your kind comments. To understand the role of the parameters stored in matrix Xt, please consult: 1) My response to previous comment of Stav Bar-Sheshet 2) The given user manual in pdf that accompanies this submission. Best of luck.

Hi Ilias,
First of all, This is a realy fine work, thank you.
I'm trying to form a controller based on the parameters which the CANFIS block generates which is the Matrix "X".
But i don't know which parameters in the generated X file for example "CANFIS_X.m" are which parameters in the rule base of the system. could you help me with this problem?

Exceptional work! very helpful toolbox, thanks

Hi Ilias,
Thanks for this. I am not sure if this can help me with my problem though. :( here's my situation.
I've already trained my data (year 2003-2016) in anfis. The problem is, when i try to 'forecast' the 2017 output, the result gives me the maximum output based on my training data. ive tried extending the range of my input data and anfis allowed me but when i tried to extend the output range in edit membership function, it gives me the same max output range.

Training data
Input range (0-1) --can be extended to more than 1
Output range (0-1)

Forecast data
Input >1
Output >1

Should i use simulink just to use .fis to ontain future estimate? The trend is increasing but fis limits the output to the training data range only.

Please help. Thank you very much!

@ ardalan ghadimi.
Just copy and paste the ANFIS/CANFIS block on the new simulink model and make sure the learned states in the respective .mat file is in the same directory as the .mdl file. You should not change the structure (NumInVars, NumRules, NumOutputs) of the original ANFIS/CANFIS block. Otherwise, the learned states .mat file will not be applicable anymore and the model will nor run. If this doesn't help send an email at my address describing the problem in detail.

Hi thank you for this helpful toolbox. I use the demo but How can I use the trained block in other simulink problems?
the toolbox provide a .mat file how can I call that and use in another simulink?
Thank you.


problem is, that I do not know, how to run models,, is explanation in your documentation? First of all, is problem for me, that I have matlab 2015??

@ matuss182 Stay Calm and describe your problem in detail in an email to me.


Thanks, but still have a problem: NFA_matlab library is failed to load,, I need to know how to solve it as soon as possible, please, someone, help me with that... :(

@ Salman sahib: You must put your data in a format pertinent to Simulink. Read the provided manual and then see how I run the library in the given demos.

Salman sahib

Hello everyone, I have 100 data sample, I dont know how to run this code, and I have 3 data inputs and 3 data targets, thanks for replying me soon, Best regards

@ Stav Bar-Sheshet
Thanks for your kind words.
The structure of file canfis_scatter.mat file is very simple because it only contains the output variable Xt:

Xt = [reshape(mean1,NumInVars*NumInTerms,1);

However, the first line of the file corresponds to time samples (or stamps).
Details regarding how Simulink stores running block outputs to .mat files can be found in Simulink documentation:

Excellent Job! the functions the modules and the great manual!

I'm looking for a way to plot the Fuzzy Inference System after the Canfis Scatter run.
Tried to figure out the canfis_scatter.mat file structure cause I assumed the premise parameters should be found there.
Could you please add an explanation? Thanks!

mazin alseadi

kishore babu

how to find anfis toolbox is exist ....

@ yulian

1) When you run the demo for the very first time, you should place a 0 at the "Initial ANFIS States [x0; d0;]" entry of the ANFIS Block Parameters form. Not in the InitFcn of the Callbacks.

2) Then you run the simulation. The learned states are stored in the file named anfis_equalize.mat in a single variable (matrix) named "anfis_states".

3) When you try to rerun the demo, in order to load the states, you uncomment the line: "load anfis_equalize.mat;" found in the OpenFcn of the Callbacks and place the name of the learned states variable (i.e. anfis_states) at the "Initial ANFIS States [x0; d0;]" entry of the ANFIS Block Parameters.

Good Luck and don't forget to provide your rating for this work.

Hi Illias, thanks for the great work. But I have a problem here. I have tried to run the demo "adapt_equalizer. I already comment "load anfis_scatter_states.mat and gave the initial state zero (in initFcn, am I right?). But I keep getting the same error when I try to simulate it. It said "error evaluating parameter ini in adapt equalizer/ANFIS grid equalizer. The other error is "undefined function and variable 'anfis_states'. Could you help me? thank you.

@ Ibrahim Seleem. I'm not sure that system identification on a Single-Input Multiple-Output System is a well-defined problem. You can always try CANFIS but success is very-very unlikely. You may consult a goos system identification book to see what is possible in system identification.

I want to make identification to single-input multi-output system. I think I'll use CANFIS .is that right ??

Anish Nair

Amazing work by Ilias. Very helpful.

fulden cantas

Thanks for the good work!

@ Alex Mao: I'm afraid that you can't increase/decrease the samples of this demo. If you want to alter the number of samples, you must modify the file SimDataGenAnfis1.m which is employed in order to create and formulate the training and checking data as required by simulink. Also, you can't alter the training/checking data sizes via the LE step function.

Alex Mao

Hi llias,

Thanks for your effort, I have tried the ANFIS_Scatter_MG based on your manual and it worked well. However, as your test data has 1000 samples, when I increase samples, the ANFIS scatter still output the first 1000 sample, can you provide some comments for solving this problem, thanks in advance.

@Richard: Please describe the problem in more detail.


I am having issues understanding the states array that the anfis_art block prints out for the purposes of reconstructing the membership functions after each time step.

Sergei P.

@ In-hwan. Yes, they are the same. You must compile combinem.c with mex and then call this function with same arguments as with comb that appears in grad_check_anfis_grid.m. Good Luck.


Thank you for your prompt response. ^^

But i can't find the "comb.c" file in your zip files.
Do you mean that "combinem.c" file is same with the "comb.c" file???

or I should find "comb.c" file for myself???

@ In-hwan. This message appears because you haven't compiled the comb.c file to an mex executable using the mex command. Apply the mex command to the given comb.c source file and then you are ready to proceed with your simulations. Function comb.c was implemented in C for faster execution. Good Luck.


When i run the file "grad_check_anfis.m"
an error happens on the function "comb()"

the error message is:
Undefined function 'comb' for input arguments of type 'double'.

Error in grad_check_anfis_grid (line 116)
precond = comb(Out1);
How can i find a file defining the function "comb()"??

@ Junho.

When you run a demo for the very first time you must comment the line "load anfis_scatter_states.mat" or similar. In the "Initial States" entry you must enter a zero indicating you start training from scratch. When the first simulation session is complete, the anfis_scatter_states.mat has been generated in the current directory. Then you must uncomment the line "load anfis_scatter_states.mat". When you bouble click the box the learned states are loaded on the workspace. Then, in the "Initial States" entry of the form, you must enter the name of the variable (matrix) that contains the learned states.


Junho (view profile)

Dear Ilias,

I was following your manual to test your ANFIS demo version to see how ANFIS works. I'm pretty sure I fellow your direction correctly but it still makes me little confused of getting ~~.mat file. First, right click and go to properties of "Double-Click to load MG Data and ANFIS States" and open "OpenFcn*" inside Callbacks tab. Then comment % "load anfis_scatter.mat" and double-click the MG data box itself. After this part, I run this program to get "anfis_scatter.mat" but it never works for me. It keeps giving me an error "anfis_scatter_states is undefined". From your guide, I have to enter the name of variable under "Initial ANFIS States" but I really have no idea which variable I have to put in to get ~~.mat file. If you don't mind, Could you give me an advise of your program?



@ mohand Ali and @ Marc O' Polo: Is the folder containing all the ANFIS/CANFIS files in your MatLab path ?

mohand Ali

Dear Marc O'Polo

I have same your problem
Error in S-function 'ANFIS_Grid_MG/ANFIS (Grid)/ANFIS': S-Function 'anfisim_grid' does not exist

if you find solve to this problem , kindly inform me

Marc O'Polo

Dear Ilias,
Thank you for the toolbox. However, I am getting the following error:
Error in S-function 'ANFIS_Grid_MG/ANFIS (Grid)/ANFIS': S-Function 'anfisim_grid' does not exist
This happens with any of the other blocks as well. Any help is much appreciated.


khaild (view profile)

the work is wonderful,thank you very much.

I do not have Adaptive Neuro-Fuzzy Inference Systems (ANFIS) Library in my simulink library.
what should I do?


khaild (view profile)

@Mohamed: Ok, thanks for the feedback. The bug was fixed. You may run every model with a single input signal form now on.

can we use the anfis scatter with only one input because an error appears

Roby, this is a problem caused by a malfunctioning (or non-existent) Signal Procesing Blockset. For more info, have a look here: . Good Luck.

roby jangam

Thank you sir
I do what ever you tell me but there is also another error is come

Failed to load library 'dspstat3' referenced by 'CANFIS_ART_Lorenz/RMS'

Caused by:
Unable to load block diagram 'dspstat3'

roby jangam

Roby, right-click on the block named "Double-click to load Lorenz Attractor Data". Select Block Properties -> Callbacks -> OpenFcn. There, together with other commands, add the following definition: sim_time = 2000; Also, note that in Simulation/Configuration Parameters/Stop Time enter: sim_time. And you're done.

roby jangam

i have a problem with CANFIS_ART_Lorenz.mdl

Error evaluating expression 'sim_time' for 'Stop time' specified in the Configuration Parameters dialog for block diagram 'CANFIS_ART_Lorenz': Undefined function or variable 'sim_time'.

so kindly please help me

roby jangam

Lejla BM

Thank you for your ANFIS and RFNN tools. It is very intresting work!

Fahrudin and Lejla

Vesna Ojleska

Nice work.
Thank you.

Please note that the recently added feature of "gradient consistency checking" is introduced in par. 7.2 of the latest version of the NFA library user's manual.

Dear Mr. Ilias Konsoulas

i have a problem with CANFIS_SCATTER
as when i enter two inputs with two error signals to get 2 outputs using MUX block it gives me an error during running by "Index exceeds matrix dimensions."

nazar dikhil

please can I get the matlab code of anfismex function


Sally (view profile)

Dear Mr.Ilias Konsoulas,
Thank you so much for your help.

To Sally and others: In the updated version of the NFA User's Manual, a new section has been added describing how to run successfully the demos on your computer. Good Luck and thanks for your patience.

Ok, in the next few days I'll add a new section on the user's guide: "NFA User's Manual v2.pdf"
to describe in more detail how to run successfully the demos. Just wait a little bit. Thanks.


Sally (view profile)

Dear Ilias Konsoulas,

Thanks for introducing the useful ANFIS library. I tried to run the demo programs but still gave me errors. Can you help me how to run that demos, Thank you so much.

Quick fix: rename library file NFA.mdl to NFA_matlab.mdl .


Ahmet (view profile)

doesnt exist NFA_matlab


Ahmet (view profile)

tying to run demo models gives erros as:

*Failed to load library 'NFA_matlab' referenced by 'ANFIS_Grid_MG/ANFIS (Grid)'
*Unable to load block diagram 'NFA_matlab'

How can i fix this? please help.




Killed some redundant variables and commands in s-function scripts. Added some new comments. Also introduced use of "if any(logical_condition)" loops instead of "if ~isempty(logical_condition) which should be a bit faster.

Improved S-function syntax. Also killed a small bug. Updated library should run a bit faster.

Fixed a bug in anfisim_scatter.m that prevented run with a single input. All models were tested for single input run successfully.

Introduced the method of gradient consistency checking. This assures the correctness of your backprop implementation. I also provided .m scripts that perform gradient checking to all (C)ANFIS functions of this library.

In the latest version of the users guide, I have included a new section describing how to make the demos runnable on your computer and briefly outlining what each demo is about.

OK, I corrected the name of the library file from NFA.mdl to NFA_matlab.mdl in order to make demos runnable.

Minor code changes, better comments and NFA User Guide corrections.

I have updated only the following form entries: a)Description, b)Tags c) Acknowledgement of other submissions.

MATLAB Release Compatibility
Created with R2011b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Discover Live Editor

Create scripts with code, output, and formatted text in a single executable document.

Learn About Live Editor