Problem with fuzzy logic membership function assignment in code

I have a problem with Optimization of fuzzy controller in code before run simulink file with the updated mfs values
fuzzy3 is fis file name with 3 inputs and 1 output
first command works
z=[Fuzzy3.input(2).mf.params]
but the seconds not work
[Fuzzy3.input(2).mf.params]= zed
it returns ... Insufficient number of outputs from right hand side of equal sign to satisfy assignment.
the first output z is 1*23 double and also the second zed ... same size
could anyone help me solve this issue.

 Accepted Answer

zc = num2cell(z);
[Fuzzy3.input(2).mf.params]= zc{:};

6 Comments

Thanks for responding
i try to complete the project ,but i have another errors
zc=num2cell(z);
[Fuzzy3.input(2).mf.params]= zc{:};
writefis(Fuzzy3,'FIS4');
sim('Fuzzytuning_ABC')
the error
writefis(Fuzzy3,'FIS4');
Error using Experiment_Fuzzy (line 58)
Error in 'Fuzzytuning_ABC/Fuzzy
control ver2/Fuzzy Logic Controller':
Initialization commands cannot be
evaluated.
Caused by:
Error using coder.internal.assert
(line 33)
Trapezoidal membership function
must have four parameters.
or another solution to convert all FIS in matlab to a code
is this possible and how?
z=[Fuzzy3.input(2).mf.params]
That will expand all of the struct entries Fuzzy3.input(2).mf(:) taking their params field and concatenating them all together into one single row. If there are any internal divisions, such as one of them having 3 parameters and another having 4 parameters, then this will not preserve any internal boundaries.
[Fuzzy3.input(2).mf.params]= zed
If zed is a vector of values concatenated together, then it has no internal structure to say which values are to go into which mf() entry. You would need to do something like
plens = cellfun(@length, {Fuzzy3.input(2).mf.params});
zedsplit = mat2cell(zed, 1, plens);
[Fuzzy3.input(2).mf.params] = zedsplit{:};
yes , i have 7 mfs , 5 with three (Triang)and 2 with 4 parameters (trap)
could you give more on code to change them?
I already gave you the code needed. The code with plens will figure out how many parameters are needed for each entry, and will split the new vector as needed to match those lengths.
Example:
%t is a structure array with fields of different sizes
for K = 1 : 5; t(K).params = 1:randi(7); end
%look at it
for K = 1 : 5; disp(t(K).params); end
1 2 1 2 3 4 5 6 7 1 2 1 2 3 4 1 2 3 4
plens = cellfun(@length, {t.params});
%replacement data
zed = 1 : sum(plens);
%do the replacement
zedsplit = mat2cell(zed, 1, plens);
[t.params] = zedsplit{:};
%look at the result
for K = 1 : 5; disp(t(K).params); end
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Yup, it works.

Sign in to comment.

More Answers (1)

Thanks for help
the last code works for fuzzy MF with cellfun and i will insert the code here

Categories

Find more on Fuzzy Logic Toolbox 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!