2

I have a matlab code and I want explain part of them like picture. or any other idea can do better.

enter image description here

\documentclass{article}

\usepackage{listings}
\usepackage{color} %red, green, blue, yellow, cyan, magenta, black, white
\definecolor{mygreen}{RGB}{28,172,0} % color values Red, Green, Blue
\definecolor{mylilas}{RGB}{170,55,241}


\begin{document}


\lstset{language=Matlab,%
    %basicstyle=\color{red},
    breaklines=true,%
    morekeywords={matlab2tikz},
    keywordstyle=\color{blue},%
    morekeywords=[2]{1}, keywordstyle=[2]{\color{black}},
    identifierstyle=\color{black},%
    stringstyle=\color{mylilas},
    commentstyle=\color{mygreen},%
    showstringspaces=false,%without this there will be a symbol in the places where there is a space
    numbers=left,%
    numberstyle={\tiny \color{black}},% size of the numbers
    numbersep=9pt, % this defines how far the numbers are from the text
    emph=[1]{for,end,break},emphstyle=[1]\color{red}, %some words to emphasise
    %emph=[2]{word1,word2}, emphstyle=[2]{style},    
}


\section*{Matlab Code}

‎\lstinputlisting{WEIGHT.m}‎


\end{document}

WEIGHT.m matlab file

clc
clear all
n=input('Please Enter Number Of Grid Point    n=');
      %-------------
      x=zeros(n,1);A=zeros(n,n);
      %-------------
      for i=1:n
        x(i)=0.5*(1-cos((i-1)*pi/(n-1))); 
      end
      for i=1:n
         for j=1:n
              Pi=1;Pj=1;
            for m=1:n 
               if m~=i  
                  Pi=(x(i)-x(m))*Pi;
               end
               if m~=j  
                  Pj=(x(j)-x(m))*Pj;
               end   
            end
            if i~=j 
               A(i,j)=Pi/((x(i)-x(j))*Pj);
            end   
         end  
         for m=1:n  
             if m~=i
                A(i,i)=A(i,i)-A(i,m);
             end
         end   
      end
3

Possible solution with tikz

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing, decorations.pathreplacing, positioning}
\usepackage[numbered,framed]{matlab-prettifier}

\begin{document}


\begin{tikzpicture}
    [%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        node distance=.2cm,
        code/.style={rectangle,draw=cyan!50,fill=cyan!20,thick,
                      inner sep=1cm,minimum size=2mm},
        place/.style={rectangle,draw=green!50,fill=green!20,thick,
                      inner sep=0cm,minimum size=6mm}           
    ]%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

     \node[code]  (A) [text width=13cm]
     { 
        ‎\lstinputlisting[%##########################
                         style=Matlab-editor,
                         basicstyle         = \mlttfamily,
                         escapechar         = ",
                         ]%#########################    
        {WEIGHT.m} 
     ‎};

     \node  (1) [left=of  A,yshift= 5.2cm] {};
     \node  (2) [below=of 1,yshift=-7mm] {};
     \draw[very thick,decorate,decoration={brace,mirror}]  (1.east) -- (2.east) 
           node[midway,left]{\Large{\textbf{1} $\leftarrow$}};

     \node  (3) [below=of 2,yshift= 3mm] {};
     \node  (4) [below=of 3,yshift=-6mm] {};
     \draw[very thick,decorate,decoration={brace,mirror}]  (3.east) -- (4.east)
          node[midway,left]{\Large{\textbf{2 important} $\leftarrow$}};

     \node  (5) [below=of 4,yshift=  3mm] {};
     \node  (6) [below=of 5,yshift=-83mm] {};
     \draw[very thick,decorate,decoration={brace,mirror}]  (5.east) -- (6.east)
          node[midway,left]{\Large{\textbf{3 Loop} $\leftarrow$}};

     \node  (7) [below=of 6,yshift= 4mm] {};
     \node  (8) [below=of 7,yshift=-1mm] {};
     \draw[very thick,decorate,decoration={brace,mirror}]  (7.east) -- (8.east)
          node[midway,left]{\Large{\textbf{4 final} $\leftarrow$}};

\end{tikzpicture}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.