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.

 採用された回答

Walter Roberson
Walter Roberson 2021 年 1 月 31 日

0 投票

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

6 件のコメント

Ahmed  shams
Ahmed shams 2021 年 2 月 1 日
編集済み: Walter Roberson 2021 年 2 月 1 日
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.
Ahmed  shams
Ahmed shams 2021 年 2 月 1 日
or another solution to convert all FIS in matlab to a code
is this possible and how?
Walter Roberson
Walter Roberson 2021 年 2 月 1 日
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{:};
Ahmed  shams
Ahmed shams 2021 年 2 月 1 日
yes , i have 7 mfs , 5 with three (Triang)and 2 with 4 parameters (trap)
could you give more on code to change them?
Walter Roberson
Walter Roberson 2021 年 2 月 1 日
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.

サインインしてコメントする。

その他の回答 (1 件)

Ahmed  shams
Ahmed shams 2021 年 2 月 4 日

0 投票

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

カテゴリ

ヘルプ センター および File ExchangeFuzzy Logic Toolbox についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by