Contour plot of data on a non-rectangular xy domain

조회 수: 34 (최근 30일)
Flavio Savarino
Flavio Savarino 2020년 7월 2일
댓글: Star Strider 2020년 7월 2일
I have a set of grid points (x and y coordinates) that define the 2D profile of a nozzle (see first figure). At each (x,y) point I have one associated Mach number value. The outputs I have saved in the Workspace are:
X = [0.940727422583647 1.07008276356436 1.22692065834036 1.36057673106938 1.47757612403718 1.58083229630319 1.67180121915360 1.75122904877083 1.81947803128837 1.87669470597913 1.64766480578674 1.96149990838104 2.24721213349415 2.51812778428731 2.78103086042419 3.04020164658987 3.29882695498003 3.55963192209535 3.82522504923162 2.36715580917139 2.75019459372898 3.12688219279990 3.50656045102632 3.89619385473159 4.30204689246559 4.73054280855190 5.18886264053406 3.24153485671916 3.74113160591086 4.26211608603718 4.81594248305852 5.41447458654436 6.07131462692823 6.80303150294865 4.38587280992005 5.08016762372871 5.84298551887043 6.69604374213440 7.66613950873088 8.78783240191376 5.98910166523484 7.02025638920920 8.21220193907888 9.61515500085347 11.2968409388847 8.39913316438290 10.0464678592194 12.0532110577635 14.5469970462624 12.3126725238430 15.1719624419344 18.8593617097915 19.2534509636518 24.7256053295867 32.9237965228157 0.201225458878551 0.401544568512606 0.600055061988792 0.795862818668550 0.988085891439809 1.17585847913729 1.35833482623908 1.53469303227466 1.70413875378622 1.86590878216921 1.88114106757577 5.17224473434695 8.20264341498603 12.5014746553367 18.7798904874541 28.1477547557704 42.4098917754965 64.5912534715622 99.9193983765138 157.741330856832]
Y = [0 0 0 0 0 0 0 0 0 0 0.468284019495316 0.688365078441413 0.870134398662408 1.03022683828011 1.17575434907956 1.31004437714614 1.43449109346876 1.54927993948610 1.65368444054394 0.249240014503638 0.482752398265359 0.714152522945603 0.951437071775017 1.20068493437125 1.46749049381185 1.75776404439260 2.07836750123525 0.246946012593601 0.504637454561617 0.782416814612824 1.08902723808264 1.43405580102017 1.82903244170465 2.28861894616418 0.271234561003887 0.578214675243649 0.933449642440055 1.35218918742599 1.85414601276354 2.46574178070085 0.323531903116927 0.716999230618729 1.20347683898331 1.81433362301026 2.59337323322718 0.416676379906227 0.960029774027971 1.67761050443268 2.63839071416433 0.580013387999989 1.39275283088429 2.54288772365924 0.877837985094477 2.20757699757850 1.46080721739494 1.00675622197270 1.02699445686726 1.06062354867880 1.10749202700132 1.16738878927277 1.24004405161225 1.32513056396653 1.42226508409270 1.53101010373798 1.65087581924160 1.66216238948742 3.77429086169118 5.44337294327854 7.44786592689250 9.87718724025564 12.7962163192375 16.2099966059658 19.9676773004198 23.5368789421467 25.4782725058883]
Mach_field = [1 1.35464909233901 1.48752328649518 1.61770816481827 1.74852078183348 1.88200933098036 2.01972736590322 2.16303431684994 2.31324472237880 2.47172035185089 1.61770816481827 1.74852078183348 1.88200933098036 2.01972736590322 2.16303431684994 2.31324472237880 2.47172035185089 2.63994047081492 2.81956659604486 1.88200933098036 2.01972736590322 2.16303431684994 2.31324472237880 2.47172035185089 2.63994047081492 2.81956659604486 3.01251142846517 2.16303431684994 2.31324472237880 2.47172035185089 2.63994047081492 2.81956659604486 3.01251142846517 3.22101964004074 2.47172035185089 2.63994047081492 2.81956659604486 3.01251142846517 3.22101964004074 3.44776847830855 2.81956659604486 3.01251142846517 3.22101964004074 3.44776847830855 3.69599811158943 3.22101964004074 3.44776847830855 3.69599811158943 3.96968541443568 3.69599811158943 3.96968541443568 4.27378122426336 4.27378122426336 4.61454149143992 5.00000000000000 1 1.35464909233901 1.48752328649518 1.61770816481827 1.74852078183348 1.88200933098036 2.01972736590322 2.16303431684994 2.31324472237880 2.47172035185089 2.47172035185089 2.81956659604486 3.01251142846517 3.22101964004074 3.44776847830855 3.69599811158943 3.96968541443568 4.27378122426336 4.61454149143992 5.00000000000000]
At the moment I am succeeding in plotting the Mach number using:
stem3(X,Y,Mach_field)
However I would like to get a rainbow coloured contour plot out of these data with a smooth variation of the Mach number within the nozzle region bounded by the longitudinal axis and the black line shown in the last figure.
Any help would be highly appreciated.

채택된 답변

Star Strider
Star Strider 2020년 7월 2일
I am not certain what you want.
Try this:
X = [0.940727422583647 1.07008276356436 1.22692065834036 1.36057673106938 1.47757612403718 1.58083229630319 1.67180121915360 1.75122904877083 1.81947803128837 1.87669470597913 1.64766480578674 1.96149990838104 2.24721213349415 2.51812778428731 2.78103086042419 3.04020164658987 3.29882695498003 3.55963192209535 3.82522504923162 2.36715580917139 2.75019459372898 3.12688219279990 3.50656045102632 3.89619385473159 4.30204689246559 4.73054280855190 5.18886264053406 3.24153485671916 3.74113160591086 4.26211608603718 4.81594248305852 5.41447458654436 6.07131462692823 6.80303150294865 4.38587280992005 5.08016762372871 5.84298551887043 6.69604374213440 7.66613950873088 8.78783240191376 5.98910166523484 7.02025638920920 8.21220193907888 9.61515500085347 11.2968409388847 8.39913316438290 10.0464678592194 12.0532110577635 14.5469970462624 12.3126725238430 15.1719624419344 18.8593617097915 19.2534509636518 24.7256053295867 32.9237965228157 0.201225458878551 0.401544568512606 0.600055061988792 0.795862818668550 0.988085891439809 1.17585847913729 1.35833482623908 1.53469303227466 1.70413875378622 1.86590878216921 1.88114106757577 5.17224473434695 8.20264341498603 12.5014746553367 18.7798904874541 28.1477547557704 42.4098917754965 64.5912534715622 99.9193983765138 157.741330856832];
Y = [0 0 0 0 0 0 0 0 0 0 0.468284019495316 0.688365078441413 0.870134398662408 1.03022683828011 1.17575434907956 1.31004437714614 1.43449109346876 1.54927993948610 1.65368444054394 0.249240014503638 0.482752398265359 0.714152522945603 0.951437071775017 1.20068493437125 1.46749049381185 1.75776404439260 2.07836750123525 0.246946012593601 0.504637454561617 0.782416814612824 1.08902723808264 1.43405580102017 1.82903244170465 2.28861894616418 0.271234561003887 0.578214675243649 0.933449642440055 1.35218918742599 1.85414601276354 2.46574178070085 0.323531903116927 0.716999230618729 1.20347683898331 1.81433362301026 2.59337323322718 0.416676379906227 0.960029774027971 1.67761050443268 2.63839071416433 0.580013387999989 1.39275283088429 2.54288772365924 0.877837985094477 2.20757699757850 1.46080721739494 1.00675622197270 1.02699445686726 1.06062354867880 1.10749202700132 1.16738878927277 1.24004405161225 1.32513056396653 1.42226508409270 1.53101010373798 1.65087581924160 1.66216238948742 3.77429086169118 5.44337294327854 7.44786592689250 9.87718724025564 12.7962163192375 16.2099966059658 19.9676773004198 23.5368789421467 25.4782725058883];
Mach_field = [1 1.35464909233901 1.48752328649518 1.61770816481827 1.74852078183348 1.88200933098036 2.01972736590322 2.16303431684994 2.31324472237880 2.47172035185089 1.61770816481827 1.74852078183348 1.88200933098036 2.01972736590322 2.16303431684994 2.31324472237880 2.47172035185089 2.63994047081492 2.81956659604486 1.88200933098036 2.01972736590322 2.16303431684994 2.31324472237880 2.47172035185089 2.63994047081492 2.81956659604486 3.01251142846517 2.16303431684994 2.31324472237880 2.47172035185089 2.63994047081492 2.81956659604486 3.01251142846517 3.22101964004074 2.47172035185089 2.63994047081492 2.81956659604486 3.01251142846517 3.22101964004074 3.44776847830855 2.81956659604486 3.01251142846517 3.22101964004074 3.44776847830855 3.69599811158943 3.22101964004074 3.44776847830855 3.69599811158943 3.96968541443568 3.69599811158943 3.96968541443568 4.27378122426336 4.27378122426336 4.61454149143992 5.00000000000000 1 1.35464909233901 1.48752328649518 1.61770816481827 1.74852078183348 1.88200933098036 2.01972736590322 2.16303431684994 2.31324472237880 2.47172035185089 2.47172035185089 2.81956659604486 3.01251142846517 3.22101964004074 3.44776847830855 3.69599811158943 3.96968541443568 4.27378122426336 4.61454149143992 5.00000000000000];
xv = linspace(min(X), max(X), numel(X));
yv = linspace(min(Y), max(Y), numel(Y));
[Xm,Ym] = ndgrid(xv, yv);
MFm = griddata(X,Y,Mach_field, Xm, Ym);
figure
contourf(Xm, Ym, MFm)
grid on
xlabel('$Length\ [\frac{x}{y_0}]$', 'Interpreter','Latex')
ylabel('$Height\ [\frac{y}{y_0}]$', 'Interpreter','Latex')
axis('equal')
producing:
Experiment to get different results.
.
  댓글 수: 2
Flavio Savarino
Flavio Savarino 2020년 7월 2일
Thank you Star Strider!
Your code works well and it gives a satisfactory output! I managed to further refine the contours and adjust a few features. Just one final question: how would you also show contours in the region encircled in red?
In this region the value of MFm is constant and equal to the one computed at the rightmost grid point (x = approx 160).
Star Strider
Star Strider 2020년 7월 2일
As always, my pleasure!
Those contours do not exist, because values do not exist in that area, and the interpolated values are NaN. (The griddata function does not allow extrapolation options.) Probably the best way to deal with that is to supply values for those regions, so griddata can fill them appropriately.
Another option is to use scatteredInterpolant, however it may not produce the result you want:
SI = scatteredInterpolant(X(:),Y(:),Mach_field(:), 'linear');
MFm = SI(Xm,Ym);
I am not aware of any other options.
.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by