2017-02-15 130 views
2

Logical circuit用於計算邏輯電路輸出

Matlab程序我不得不計算關於該邏輯電路每個輸出,和我沒有與電子任何經驗。

因此,我搜索了符號的含義,並在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 

回答

2

你的代碼將產生正確的結果,但你可以使用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