% Draw the result of a finite difference demo for electrical impedance
% tomography. This routine is for 1D demos.
%
% Inputs:
% N            size of the grid is 1xN
% condvec      vector of electric conductivity values, length N-1
% fignum       figure window number
%
% Samuli Siltanen February 2025

function EIT_FD_demo1D_conductivity_plot(N,condvec,fignum)

% Set geometrical parameters
geometry_set;

% Check the size of the conductivity vector
[crow,ccol] = size(condvec);
if min(crow,ccol)>1
    error('Conductivity vector should be a vector, not a matrix')
end
cN = length(condvec);
if ~(cN==(N-1))
    error('Conductivity vector length should be length(potvec)-1')
end

% Record maximum conductivity
condmax = max(condvec);

% Create plot window
figure(fignum)
clf

% Left boundary has conductivity = 1
curr_cond_color = colorscale_cond(1,condmax);
p = patch([0 Dx/2 Dx/2 0],[0 0 Dx Dx],curr_cond_color);
set(p,'edgecolor',curr_cond_color)
hold on
% Right boundary has conductivity = 1
p = patch(N-Dx/2+[0 Dx/2 Dx/2 0],[0 0 Dx Dx],curr_cond_color);
set(p,'edgecolor',curr_cond_color)
% Internal conductivity
for jjj = 1:N-1
    curr_cond_color = colorscale_cond(condvec(jjj),condmax);
    p = patch(jjj-Dx/2+[0 Dx Dx 0],[0 0 Dx Dx],curr_cond_color);
    set(p,'edgecolor',curr_cond_color)
end

% Plot grid
p1 = plot([0 N],[0 0],'k','linewidth',lwidth_grid);
set(p1,'color',color_gridline)
hold on
p2 = plot([0 N],[Dx Dx],'k','linewidth',lwidth_grid);
set(p2,'color',color_gridline)
for jjj = 1:N+1
    p3 = plot((jjj-1)*[Dx Dx],[0 Dx],'k','linewidth',lwidth_grid);
    set(p3,'color',color_gridline)
end

% Axis settings
axis([-2*Dx (N+2)*Dx -2*Dx 3*Dx])
axis equal
axis off

