Help with Plotting a time and space dependent variable (Shrinking Core Model)

Hello MATLAB Community,
I hope everyone is doing great and staying safe and healthy. I am coding a time and space dependent property of a particle that is undergoing a chemical reaction. The reaction front basically moves from the outer most surface towards the center (Shrinking Core Model). I have succesfully coded it using nested FOR loops but I am having problems in extracting results and plotting them. I would be really grateful if someone can help me as this project report is due in a few days. The code is also attached.
  1. The figure below show the change in target variable as a function of radius, and each curve is for a specific time value. For example, 1 is the curve for time 1, 2 is the radius for time 2 and so on. I need help to convert this to a surface map with radiua as x variable, time as y variable and PCO2 as z variable.
2. The second thing I need help with is making a diagram. the sketch below shows what I have in mind. Right now my code can give the values of inner and outer radius at each time and also how PCO2 (the target variable) changes in the yellow region. I want to make this figure and display the values of PCO2 in the yellow region as acolor spectrum (high-red, low-blue). Any help would be greatly appreciated.
3. The last thing I need help with is putting a slider for time so I can automatically jump to the required time. Someting like an interactive graph of PCO2 vs. Radius witha time slider.
Once again THANKYOU for your attention and I would really appreciate any help.
The Code is attached

7 Comments

  • Creating a surface
Just write each curve data into 2d matrix and use surf
  • Diagram
Once you have your 2D matrices with CO2 and Radius you can convert them into X Y data
First scale the data
T1 = (T-minT)/(maxT-minT)*2*pi; % scale time between 0 .. 2*pi
R1 = (R_minR)/(maxR-minR)+0.5; % scale radius 0.5 .. 1.5
[X,Y] = pol2cart(T1,R1);
surf(X,Y,CO2)
Hi Darova,
Thank you very much for your response. So T1 and R1 here are the current time and radius, respectively?
Also for creating the surface, I am having trouble visualizing it, as my storage matrix forP CO2 with respect to R [PCO2 ; R] is changing by 1 every timestep. So if at time0 i have 10 rows, at time1 i will have 11 rows and so on and so forth. Can you please explain it in a little bit detail, preferably with an example. I would really appreciate it. Anyways, I am already thankful for this answer.
  1. as @Darova wrote, convert it to 2D matrix, + 1D for the value of each matrix element, and plot it with surf. You can initialize your matrix with the max dimensions expected using the initial values for your PCO2 i.e. PCO2=ones(ntime,nR)*PCO2_initial
  2. Your data in [1] as f(r,t) to make this plot you need to expand it with symmetry to f(r,theta,t) and then plot a POLAR contour. If you do not prefer the POLAR plot, transform your coordindates using POL2CART. Afterwards, select a fixed color for your outside and inside, of your torus, values to create the effect you want. I think, setting these values to NAN or selecting proper LIM could cause the effect you want.
  3. for the slider, I have used this https://www.mathworks.com/help/matlab/ref/uislider.html and the example described here https://www.mathworks.com/matlabcentral/answers/56236-how-to-constantly-update-a-plot-off-of-a-slider-being-pulled
Thankyou very much Dr. Kakosimos. I really appreciate this.
Store values as (inside for loop)
R(1:m,t) = StrM1(:,1);
CO2(1:m,t) = StrM2(:,2);
Create time matrix as
T = repmat(1:n,size(R,1),1);
Thankyou very much. I will try this approach.

Sign in to comment.

Answers (0)

Categories

Find more on Chemistry in Help Center and File Exchange

Products

Release

R2019b

Community Treasure Hunt

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

Start Hunting!