用于计算逻辑电路输出的 Matlab 程序
Matlab program for calculate logical circuit outputs
我必须计算这个逻辑电路上的每个输出,而且我没有任何电子经验。
所以,我搜索了符号的含义,并在 Matlab 上构建了我的程序。
如果我做错了或者指出更好的方法,有人可以看看并帮助我吗?
这是我的 Matlab 代码:
for A = 0 : 1
for B = 0 : 1
for C = 0 : 1
for D = 0 : 1
if A ~= B
E = 1;
else
E = 0;
end
if B == 0
F = 1;
else
F = 0;
end
if C == 0
G = 1;
else
G = 0;
end
if E == 1 && F == 1 && C == 1
H = 1;
else
H = 0;
end
if G == 1 || D == 1
I = 0;
else
I = 1;
end
if H == 1 && I == 1
Y = 0;
else
Y = 1;
end
disp(['Se A=' num2str(A) ', B=' num2str(B) ', C=' num2str(C) ' e D=' num2str(D) ' => Y=' num2str(Y)]);
end
end
end
end
您的代码将产生正确的结果,但您可以将 MATLAB's built-in functions 用于 布尔代数 .
for A = 0 : 1
for B = 0 : 1
for C = 0 : 1
for D = 0 : 1
Y = ~((xor(A,B) & ~B & C) & ~(~C | D));
disp(['Se A=' num2str(A) ', B=' num2str(B) ', C=' num2str(C) ' e D=' num2str(D) ' => Y=' num2str(Y)]);
end
end
end
end
我必须计算这个逻辑电路上的每个输出,而且我没有任何电子经验。
所以,我搜索了符号的含义,并在 Matlab 上构建了我的程序。
如果我做错了或者指出更好的方法,有人可以看看并帮助我吗?
这是我的 Matlab 代码:
for A = 0 : 1
for B = 0 : 1
for C = 0 : 1
for D = 0 : 1
if A ~= B
E = 1;
else
E = 0;
end
if B == 0
F = 1;
else
F = 0;
end
if C == 0
G = 1;
else
G = 0;
end
if E == 1 && F == 1 && C == 1
H = 1;
else
H = 0;
end
if G == 1 || D == 1
I = 0;
else
I = 1;
end
if H == 1 && I == 1
Y = 0;
else
Y = 1;
end
disp(['Se A=' num2str(A) ', B=' num2str(B) ', C=' num2str(C) ' e D=' num2str(D) ' => Y=' num2str(Y)]);
end
end
end
end
您的代码将产生正确的结果,但您可以将 MATLAB's built-in functions 用于 布尔代数 .
for A = 0 : 1
for B = 0 : 1
for C = 0 : 1
for D = 0 : 1
Y = ~((xor(A,B) & ~B & C) & ~(~C | D));
disp(['Se A=' num2str(A) ', B=' num2str(B) ', C=' num2str(C) ' e D=' num2str(D) ' => Y=' num2str(Y)]);
end
end
end
end