How can i write a MATLAB function named dedbi that takes input xtx as string and returns another string xtxx as output.

后端 未结 5 860
遇见更好的自我
遇见更好的自我 2021-01-22 09:38

dedbi reverse the words that is, ‘a’ will be replaced by ‘z’, ‘b’ will be replaced by ‘y’, ‘c’ will be replaced by ‘x’ and so on. dedbi will do the same for capital letter t

5条回答
  •  庸人自扰
    2021-01-22 10:22

    Pseudo code:

    function out = func_name(in)
        in = array of ascii values from original in values (can be done with one command)
        out = vector if zeros the size of in (one command)
        loop through all numbers of in
            ch = current char ascii value (just because it is easier to write ch than in(index) in my opinion)
            if ch is btw 65 and 96
                subtract 65 so ch is 1-26
                find 26-ch (invert)
                add 65 so ch is 65-96
            if ch is btw  97 and 122
                do the same as above with adjusted numbers
            end if
            out(index_of_for_loop) = ch
        end loop
    end function
    

    Note: In general, it is best to avoid code that has many copy-paste section because it can be difficult to edit quickly.

提交回复
热议问题