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

I need to know how to enter this into MATLAB line for line Thank you Problem Sta

ID: 3750969 • Letter: I

Question

I need to know how to enter this into MATLAB line for line Thank you Problem Statement Given a binary number of length at most 6, convert it to the decimal representation. For example, the binary number 100 is 4 in decimal. Do not use existing matlab function to do the conversion. The functions allowed for this assignment are: input(), str2num) length() and fprintf). If you want to you functions not listed here, ask me for permission Input A binary number of length at most 6. But the length can be anything between 1 and 6 Output The number in decimal. If the length of the input is more than 6, give an error message You can use the function length() to check the input length You can use leading O's if the length of the input is less than 6. Sample Outputs&Test Cases Test1 Enter the binary number: 100 The number in decimal is 4 Test2 Enter the binary number: 100100 The number in decimal is 36 5 Test3 The length of the binary number can not exceed 6. Program Complexity My solution code for this program is 13 lines Notes Do not hard code the test cases. I may use other test cases not listed here to grade

Explanation / Answer

---------------------binaryToDecimal.m-------------------

function [dec] = binaryToDecimal(bin)

   

  dec = 0;

   

    % travere through the string

    for i = 1 : length(bin)

   

        % str2num() convert string into number

        % length() returns the length of string

        dec = dec + str2num(binarystring(i)) * 2^(length(bin) - i);

   

    end

end

----------------------main.m------------------

prompt = 'Enter the binary number : ';

% read string from user
bin = input(prompt , 's');

fprintf('The number in decimal is %f ', binaryToDecimal(bin));