Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MATLAB - The display operates on a binary system, where 0 indicates that a given

ID: 3776402 • Letter: M

Question

MATLAB - The display operates on a binary system, where 0 indicates that a given cell is off and 1 indicates that the cell is on. For example, the display will be blank if all 7 cells are off, i.e. 0 0 0 0 0 0 0, and the number 8 (shown above) would be indicated by having all cells on, i.e. 1 1 1 1 1 1. Note, these 0’s and 1’s are not the binary representations of the one-digit value, but the active cells in the order as indicated above. Write a MATLAB function that accepts any positive number less than 100 and returns the appropriate output values for TWO 7-cell, numeric LCDs. Each digit should have its own corresponding and readily identifiable output.

For example) function (44)

ans= First LCD: 0 1 1 1 0 1 0

3 6 4 1 7 2 5

Explanation / Answer

Code-

function[d1,d2]= dig(n)
    if (n>=100)||(n<1)
        disp('Incorrect number')  
    else
        [d1,d2]=cont(n);
    end  
end

function [t1,t2]= cont(n)
    n1=n/10;
    if(n1>1)
        n1=floor(n1);
    else
        n1=ceil(n1);
    end
    n2=rem(n,10);
  
      
    if(n>10)
  
        if (n1==1)
            t1='0010010';
        elseif (n1==2)
            t1='1011101';
        elseif(n1==3)
            t1='1011011';
        elseif(n1==4)
            t1='0111010';
        elseif(n1==5)
            t1='1101011';
        elseif(n1==6)
            t1='1101111';
        elseif(n1==7)
            t1='1010010';
        elseif(n1==8)
            t1='1111111' ;     
        elseif(n1==9)
            t1='1111010';
        end
    else
        t1='0000000';
    end
  
  
    if (n2==1)
        t2='0010010';
    elseif (n2==2)
        t2='1011101';
    elseif(n2==3)
        t2='1011011';
    elseif(n2==4)
        t2='0111010';
    elseif(n2==5)
        t2='1101011';
    elseif(n2==6)
        t2='1101111';
    elseif(n2==7)
        t2='1010010';
    elseif(n2==8)
        t2='1111111';     
    elseif(n2==9)
        t2='1111010';
    end    
end

Examples-

>> [a,b]=dig(9)

a =

0000000


b =

1111010

>> [a,b]=dig(11)

a =

0010010


b =

0010010