Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

ECE question...MATLAB...function that performs half-adder and full-adder?

Write a MATLAB function the performs the operation of a half-adder, call it half_add. The

function should have two inputs, a and b, and return two outputs, X and c. Then, write another

function, call it full_add, that invokes half_add to perform the operation of a full adder. The

function full_add should have three inputs, a, b and c_in, and return two outputs, s and c_out.

Finally, write a program that uses the function full_add to find and display s and c_out for each

possible combination of a, b, and c_in.

This is what I have so far for the half-adder:

clear all; clc

function [(X,c)] = half_add( (a,b) )

%function to perform the operation of a half-adder

% a and can be logical or numeric binary vectors

a = logical([0 0 1 1]); b = logical([0 1 0 1]); % assigning a and b

for k = 1:4

X(k) = xor(a,b)

c(k) = a(k) & b(k)

end

end

please explain me what to do after this...

Thank you

1 Answer

Relevance
  • Anonymous
    9 years ago
    Favorite Answer

    What you're doing doesn't work.

    In general, a function has input/output parameters.

    Input parameters come from the outside of the function.

    Output parameters are calculated within that function.

    Start your function like this:

    function [X, c] = half_add(a, b)

    ... code

    ... code

    ... do whatever

    Call that function from another script or from your main code, or even from your command window.

    You define parameters somehow there and then you call the function. For example,

    a = [0 0 1 1];

    b = [0 1 0 1];

    [X, c] = half_add(a, b)

    You get your answers in X and in c.

    .

Still have questions? Get your answers by asking now.