MATLAB Answers

Contour plot of concentration of chemical species

37 views (last 30 days)
SS
SS on 10 Nov 2019
Commented: Star Strider on 14 Nov 2019
Hi. I am releasing a chemical species CHX (N units) in a chamber. The size of the chamber is 100 X 100 X 100 cms^3. I want to plot the contour/surface plot of concentration of this chemical species in the chamber at different spatial locations.
I want to look at the concentration profiles overlapped or plotted on one plane, say X-Y plane (100 X 100 cm^2).
I am using a digital chemical analyzer which gives the X and Y vectors, X and Y which give the spatial location. Each and every (X,Y) corresponds to a spatial location at which the chemical species is present.
For example, if a given (X,Y) shows up "m" times it, means that there are "m" units of that species at that location. In my surface plot, at that particualr (X,Y), I want the value to be m/N (with some colormap). The same is with other (X,Y) locations.
Can someone help me with this?

  0 Comments

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 10 Nov 2019
Try this example:
xy = randi(9, 100, 2); % Matrix Of ‘x’ and ‘y’ Positions
[Uxy,ia,ic] = unique(xy, 'rows'); % Unique Rows
tally = accumarray(ic, 1); % Tally Numbers Of Unique Row Repeats
Freq = [Uxy, tally]; % Concatenated Matrix
xv = min(xy(:,1)):max(xy(:,1)); % ‘x’ Vector For Interpolation
yv = min(xy(:,2)):max(xy(:,2)); % ‘y’ Vector For Interpolation
[X,Y] = ndgrid(xv,yv); % Create Interpolation Grid
Z = griddata(Freq(:,1), Freq(:,2), Freq(:,3), X, Y); % Interpolated Grid Of ‘tally’ Values
figure
contourf(X, Y, Z) % Contour Plot
colorbar
Experiment to get the result you want.

  8 Comments

Show 5 older comments
Star Strider
Star Strider on 11 Nov 2019
My pleasure.
I would have to see your data in order to comment. It may be that your data simply show a more-or-less uniform distribution rather than local concentrations. (Note that the vectors I used to test this were random integers, not actual data.)
If my Answer helped you solve your problem, please Accept it!
SS
SS on 14 Nov 2019
Hi Star Strider. I have a question. Is there any function which calculates the intensity at a grid cell based on the PDF (averaging of the Z data points in that cell) rather than interpolation scheme which griddats function does?
Star Strider
Star Strider on 14 Nov 2019
I am not certain that I understand what you are asking. The griddata function is necessary to create the matrices to do the contour plot. There are several different interpolation methods available in griddata, so perhaps one of them (perhaps 'nearest') is what you are looking for. (To the best of my knowledge, you cannot define your own interpolation scheme to use with griddata or the other interpolation algorithms.)

Sign in to comment.

More Answers (0)

Sign in to answer this question.


Translated by