How to resolve the error: the variable fuzout(1,i) cannot save fuzout = evalfis(fis, trainin)
6 views (last 30 days)
Show older comments
Hello, i'm getting an error in my code:
Unable to perform assignment because the indices on the left side are not compatible with
the size of the right side.
Error in anfisloop (line 6)
[fuzout(1,i),trnRMSE(1,i)] = evaltrainset(T(1,i),trainin,trainou);
my code: the function i'm calling:
this function will create 5 models each one will be in a column in T[].
so T(1,1) is the first model, T(1,2) the second .....
the idea of what i want to do is:
create a variable (here fuzout[]) that will stack in each column the output of a model
and another variable that will stack in each column the RMSE of a model.
function [T,fuzout,trnRMSE] = anfisloop(trainin,trainou,testin,testout,fis)
epoch=5;
for i = 1:epoch
opt=anfisopt(testin,testout,fis,i);
T(1,i) = anfis([trainin trainou],opt);
[fuzout(1,i),trnRMSE(1,i)] = evaltrainset(T(1,i),trainin,trainou);
end
end
the function evaltrainset that the precious function call:
evalfis is a matlab's function
function [fuzout,trnRMSE] = evaltrainset(fis,trainin,trainout)
fuzout = evalfis(fis,trainin);
trnRMSE = norm(fuzout-trainout)/sqrt(length(fuzout));
end
how i am calling the function :
>> [A,fuzout,trnRMSE]=anfisloop(trainin,trainout,testin,testout,fis)
please help.
Answers (1)
Sam Chak
on 25 Apr 2025
I am revisiting the problem after nearly three years. I created dummy data and resolved the issue involving the evaltrainset() command in the anfisloop() function. The reason you are unable to perform the assignment in that line is that the right side, evalfis(fis, trainin), returns a vector, while the left side, fuzout(1,i), is only capable of storing a single value at each loop. The correct syntax for the left side should be fuzout(:,i).
%% custom function "anfisloop" to create one FIS in each loop
function [T, fuzout, trnRMSE] = anfisloop(trainin, trainou, testin, testout, fis, epoch)
for i = 1:epoch
opt = anfisOptions('InitialFIS', fis, 'EpochNumber', i, 'ValidationData', [testin, testout]);
opt.DisplayANFISInformation = 0;
opt.DisplayErrorValues = 0;
opt.DisplayStepSize = 0;
opt.DisplayFinalResults = 0;
T(1,i) = anfis([trainin trainou], opt);
[fuzout(:,i), trnRMSE(1,i)] = evaltrainset(T(1,i), trainin, trainou);
end
end
%% custom function "evaltrainset" to evaluate FIS
function [fuzout, trnRMSE] = evaltrainset(fis, trainin, trainou)
fuzout = evalfis(fis, trainin);
trnRMSE = norm(fuzout - trainou)/sqrt(length(fuzout));
end
%% dummy data
testin = linspace(-1, 1, 201)';
testout = 2/pi*atan(5*pi/2*testin);
trainin = testin;
trainou = erf(5*trainin);
%% generate initial FIS
fis = genfis(testin, testout);
%% train ANFIS model
epoch = 5;
[T, fuzout, trnRMSE] = anfisloop(trainin, trainou, testin, testout, fis, epoch);
%% display predictions of ANFIS models
figure
plot(trainin, fuzout), grid on
title('Plots of fuzout')
%% display prediction accuracy of each ANFIS model
disp(trnRMSE)
0 Comments
See Also
Categories
Find more on Fuzzy Inference System Tuning in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!