how to plot each raw and each column of the matrix?

I have to get graphs similar to attached file2.JPG
function pde1
clc; clear; close all
m=1; %cylindrical geometry
R=3e-3; %radius of lumen (m)
dm = 13.04e-6; % TM thickness (m)
r1 =R + dm; %radius of outer surface of membrane (m)
L=1.2; %height of the membrane (m)
Q = 6.5e-9; %volumetric flow rate
D=1.76e-9; %diffusion coefficient of ammonia in liquid m2/s
RT = 2477.6; %J/mol
H = 1.62; %Henry's law constant Pam^3/mol
u0= 285.1; %inflow concentration
zn=10; % grid line z (actually z denoted by t
xn = 10; % grid-steps channel x-axis(radius side)
xmesh = linspace(0,R,xn);
zspan =linspace(0,L,zn); %counter point of length% spatial solution domain (m)
dx = 1/(xn-1);
x = [xmesh]; %x vector
z =[zspan]; %t vector
U_a = Q/3.14/R^2; % average velocity
sol =pdepe(m,@pdefun,@pdeic,@pdebc,xmesh,zspan);
u=sol(:,:,1)
surf(x,z,u)
xlabel('radi')
ylabel('height')
figure
plot(x/R,u(end,:)/u0)
xlabel('radi')
ylabel('concentration')
figure
plot(z/L,u(:, end)/u0)
xlabel('height')
ylabel('c')
figure
hold on
for i =1:zn
plot(x
/R,u(i,:),'.k')
hold off
end
xlabel('position ')
ylabel('concentration in every row')
figure
hold on
for ii =1:xn
plot(z/L,u(:,ii),'.')
hold off
end
xlabel('position ')
ylabel('concentration in every colomn')
%%
function [c,f,s]= pdefun(x,z,u,DuDx)
c = U_a/D;
f = DuDx;
s=0;
end
%% initial condition
function u0 = pdeic(x)
u0 =285.1;
end
%%
function [pl,ql,pr,qr] = pdebc(xl,ul,xr,ur,z)
pl=0;
ql=1;
pr=u0;
qr=1;
end
save('results.mat');
end

4 comentarios

Stephen23
Stephen23 el 19 de Dic. de 2018
Editada: Stephen23 el 19 de Dic. de 2018
Note that in MATLAB square brackets are a concatenation operator, so on these lines they are totally superfluous:
x = [xmesh];
z = [zspan];
The very first line of code inside your function is not a good start:
clc; clear; close all
As the function has no input arguments its workspace is totally empty anyway, so clear does absolutely nothing. Cearing the command window does not seem particularly relevant to the functionality of this code.
"how to plot each raw and each column of the matrix?"
Either use a loop, or plot them all at once using a matrix.
madhan ravi
madhan ravi el 19 de Dic. de 2018
is that plot which comes inside the loop? which one are you trying to plot?
@madhan ravi, yes
I creat the loop because it should read every row/column
@stephan,
Actually i used the loop,
but it doen't work

Iniciar sesión para comentar.

Respuestas (1)

Akshay Khadse
Akshay Khadse el 27 de Dic. de 2018

0 votos

Assuming that you are facing difficulty in superimposing graphs, you could try any of the following suggestions:
1) Remove the 'hold off' from inside the 'for' loop. In your code, the 'hold off' during each iteration of 'for' loop causes the previous line to get replaced.
2) You could direclty plot the matrices as described in the following MATLAB Answers Page:

Productos

Versión

R2017b

Etiquetas

Preguntada:

el 19 de Dic. de 2018

Respondida:

el 27 de Dic. de 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by