Error using min Matrix dimensions must agree.

Greetings ... I will be new in matlab and in this community, I am going to you because I have a small problem with a project, which tries to make a fuzzy controller ... I got a code from a controller that made a few Changes insignificant, but it is not working, and shows me an error in the use of the min () function. Someone who can help me with this problem please
%
paso = 0.01;
valCong=0:paso:1;
PC=trapmf(valCong,[0 0 0.1 0.35]);
MC=trimf(valCong,[0.2 0.5 0.8]);
AC=trapmf(valCong,[0.65 0.9 1 1]);
paso2=0.1;
tiempo=0:paso2:55;
PTV=trapmf(tiempo,[0 0 7.5 15]);
MTV=trimf(tiempo,[10 27.5 45]);
LTV=trapmf(tiempo,[40 47.5 55 55]);
nivCong=0.5;
n=find(valCong==nivCong);
B1 = min(PTV,PC(n));
B2 = min(MTV,MC(n));
B3 = min(LTV,AC(n));
B = max(B1,max(B2,B3));
TV = defuzz(tiempo,B,'centroid');
tiempoVerde=round(TV,0);
Este codigo me da el siguiente error
"Error using min
Matrix dimensions must agree.
Error in Oquendo_Calama (line 53)
B1 = min(PTV,PC(n));"

Antworten (2)

John D'Errico
John D'Errico am 11 Jan. 2017
Bearbeitet: John D'Errico am 11 Jan. 2017

0 Stimmen

Apparently, PTV is a matrix. Right? What size is that matrix?
Apparently, PC(n) is a matrix. Right? What size is that matrix?
They are not the same size. Read the error message. What sense would it make to try to take the min between a 3x3 and a 2x2 matrix? None. While I don't know the actual sizes of your matrices, the above statement still applies.

1 Kommentar

Stephen23
Stephen23 am 11 Jan. 2017
Cesar Herbas's "Answer" moved here:
What happens is that I try to do is to program my own fuzzy controller, and that's why I'm not using Fuzzy Logic Toolbox, so far as PTV and PC are not actually arrays but rather they are fuzzy sets, and I explained that "B1 = Min (PTV, PC (n)) "makes a cut of the PTV set at the height of the fusing value 'n' and that value stores it in B1

Melden Sie sich an, um zu kommentieren.

Walter Roberson
Walter Roberson am 11 Jan. 2017

0 Stimmen

Your find() operation is returning the empty matrix for n.
You have find(valCong==nivCong) which attempts to check for bit-for-bit equality between the floating point number nivCong in the vector 0:paso:1 where paso is not an integer (paso = 0.01). Due to accumulated floating point roundoff, there might not be any entry that exactly equals 0.5.
You should consider using
[tf, n] = ismembertol(nivCong, valCong);
and you should check to be sure that tf returns true (if it is false, no entries matched to within tolerance.)

Kategorien

Mehr zu Fuzzy Logic in Simulink finden Sie in Hilfe-Center und File Exchange

Tags

Gefragt:

am 11 Jan. 2017

Beantwortet:

am 11 Jan. 2017

Community Treasure Hunt

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

Start Hunting!

Translated by