How to represent my Matlab matrix values in the following lattice-tree form? -


My mesh fiber has my values ​​as shown in fig 1:

Enter image details here Finish 1: Format the values, as currently displayed in Matlab for my code

Now I would like to express these values ​​as a lattice tree, as shown in Fig. 2 (note 2 figures are not equal in nature , And fig 2 are for demonstration purpose only). How can I modify my code in matlab so that the result looks as if the tree format shown in figure 2?:

 Enter image details here fig 2: the format of values, as I would like to display in my Matlab result

My code is: BLOV_general (S0, K, sigma, r, t, nColumn) %% static parameter del_T = T. / nColumn; % Where n is the number of columns = exp (sigma. * Sqrt (del_T)); D = 1. / u; P = (sum (r * del_T) -d.) ./ (u-d); A = exp (-r * del_T.); Starting %% Latinos string = zero (encoded + 1, NCom + 1); BLOV_lattice = Zero (nColumn + 1, nColumn +1); Development of lattice for %% i = 0: n column for j = 0: i string (j + 1, i + 1) = s. * (U.J.) * (D. ^ (I-J)); End end n column BLOV_lattice (i + 1, nColumn + 1) = maximum (Strei (i + 1, nColumn + 1) -K, 0) for I = 0; For I = nColumn, for int: -1: Jammu = 0: i-1 BLOV_lattice (j + 1, i) = a * ((1-p). * BLOV_lattice (j + 1, i + 1)) + (p. * BLOV_lattice (j + 2, i + 1)); End price = BLOV_lattice (1,1);

If your goal is to reformat an upper triangular matrix (as the figure 1) is arranged in a structure similar to a tree (as shown in figure 2) with non-zero values ​​with a matrix, so you can complete it using the function. Here is an example using 5-by-5 ​​matrix:

  & gt; & Gt; A = triu (reshape (1: 25,5,5))% # A sample upper triangular matrix A = 1 6 11 16 21 0 7 12 17 22 0 0 13 18 23 0 0 9 24 0 0 0 0 25 & Gt; & Gt; N = size (A, 1); % # A and gt; & Gt; The size of rows and columns in b = full (spdiags (spdiags (a), (1-n): 2: (n-1), zero (2 * n-1, n)) b = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 11 0 22 0 6 0 17 0 1 0 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 25   < / Div> 

Comments