Plotting data from a matrix: Showing shaded area on graph

Dear all,
I have the following situation:
  • I have a solution, with both a certain weight percent of polymer, C_wt, and a certain molarity of salt, C_NaCl.
  • I have made a function to find the total molarity of salt in the solution (since the polymer contains ions that are released in the solution). Here this important part is that the C_Cl give me the total Cl ions in the solution.
function [C_Cl] = counterionfunc(C_wt,C_NaCl, ps)
C_pdad = C_wt*10/ps.mw_pdad_monomer; %Concentration of monomer units: mol/L
C_Cl_pdad = C_pdad; %mol/L
C_Cl = C_Cl_pdad + C_NaCl; %mol/L
end
Now, I would like to create a figure, in which I show the NaCl molarity, C_NaCl, on the x axis, the weight percent of the polymer, C_wt, on the y-axis, and then shade the areas in which the total Cl ions in the solution are less than the solubity limit (4.38 M). I've made a small rough sketch below:
What I have tried so far, is below. First I make a struct to put in my values. Then I vectors for my C_wt (from 0 to 100 wt%) and C_NaCl (from 0 to 5 molar). Now when I put this into the function, I get a matrix C_Cl. Now I'm stuck... How do I continue? Your help would be much appreciated!
%constants put into a struct
ps = struct;
ps.mw_pdad_monomer = (8*12.01) + (16*1.01) + (1*14.007) + (1*35.45); %C8-H16-N-Cl:
ps.mw_pss_monomer = (8*12.01) + (7*1.01) + (16.00 *3) + (1*32.06) + (22.99); %C8-H7-O3-S-Na:
ps.mw_nacl = 58.44; %g/mol
% Max solubility is 25.6 g/100 ml of water at 20*C
sol_limit_molarity_nacl = ((25.6/ps.mw_nacl)/ 0.100); %is 4.38M
C_wt = [0:1:100]; %Weight percent of polymer
C_wt = C_wt'; %Transpose matrix
C_NaCl = [0:1:5];%molarity of NaCl
%Input values into function
[C_Cl] = counterionfunc(C_wt,C_NaCl, ps);

 채택된 답변

Mathieu NOE
Mathieu NOE 2021년 6월 1일
hello Isabella
this is my suggestion and how it looks as a plot
you may have to tweka the labels / titles etc ...
hope it helps
%constants put into a struct
ps = struct;
ps.mw_pdad_monomer = (8*12.01) + (16*1.01) + (1*14.007) + (1*35.45); %C8-H16-N-Cl:
ps.mw_pss_monomer = (8*12.01) + (7*1.01) + (16.00 *3) + (1*32.06) + (22.99); %C8-H7-O3-S-Na:
ps.mw_nacl = 58.44; %g/mol
% Max solubility is 25.6 g/100 ml of water at 20*C
sol_limit_molarity_nacl = ((25.6/ps.mw_nacl)/ 0.100); %is 4.38M
C_wt = [0:0.1:100]; %Weight percent of polymer (increased resolution for better rendering)
C_wt = C_wt'; %Transpose matrix
C_NaCl = [0:0.01:5];%molarity of NaCl (increased resolution for better rendering)
%Input values into function
[C_Cl] = counterionfunc(C_wt,C_NaCl, ps);
% output plot
C_Cl(C_Cl>sol_limit_molarity_nacl) = NaN; % remove values above limit
figure(1);
colormap(flipud(hot))
imagesc(C_NaCl,C_wt,C_Cl)
xlabel('C NaCl');
ylabel('C wt');
set(gca,'YDir','normal')
hcb=colorbar;
hcb.Title.String = "Total CL";
hcb.Title.FontSize = 13;
function [C_Cl] = counterionfunc(C_wt,C_NaCl, ps)
C_pdad = C_wt*10/ps.mw_pdad_monomer; %Concentration of monomer units: mol/L
C_Cl_pdad = C_pdad; %mol/L
C_Cl = C_Cl_pdad + C_NaCl; %mol/L
end

댓글 수: 2

Thank you so much! This was very helpful :)
My pleasure !

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Language Fundamentals에 대해 자세히 알아보기

질문:

2021년 6월 1일

댓글:

2021년 6월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by