Contour not plotting correctly in MATLAB--works in Mathematica

조회 수: 3 (최근 30일)
Emma Reznick
Emma Reznick 2018년 3월 19일
댓글: Abraham Boayue 2018년 3월 20일
I've been trying to get a contour to plot in MATLAB where I have been running analysis on my data, but it will not plot correctly. I have translated the formula into Mathematica (just get rid of all of the matrix '.' operations) and it plots correctly (below).
This is the formula that it should be plotting:
And this is the code I have been running on MATLAB to no avail (it seems to scale with S and F input ranges):
%Establish Constants from Literature
s_u = 1.202^2;
f_u = (168/60)^2;
E0 = 24/60;
%Generate Matricies
f = linspace(0,1);
s = linspace(0,2.5);
[S,F] = meshgrid(s,f);
Z = ((s_u)*(f_u)*E0)./(S.*F.* (s_u-(S.^2)).* (f_u-(F.^2)) );
%Plot
contour(F,S,Z)
Any help would be much appreciated!

채택된 답변

Abraham Boayue
Abraham Boayue 2018년 3월 20일
Hey Emma, what happens if you divide by zero, looks like you are doing just that (S and F will become zero at some point in your code). This is not a solution. It's just to allow you see clearly what's going on in the background of your code.
%Generate Matricies (Increase the figure window to see clearly)
f = linspace(-30,20, 30); % some combinations of f and s will include zero
s = linspace(-20,20,30); % in S or F giving an undesirable result, since division
% by zero is not allowed.
[S,F] = meshgrid(s,f);
ss = find(S==0); % Check for zeros in S and F
ff = find(F==0); % Try to make some conditions to avoid dividing by zero.
Z = ((s_u)*(f_u)*E0)./(S.*F.* (s_u-(S.^2)).* (f_u-(F.^2)) );
%Plot
Zmin = min(min(Z));
Zmax = max(max(Z));
spacing = 0.005; % draw more circles between each interval for smaller values
topspace = 1; % increase the upper limit circles
levels=[Zmin:spacing:1,1,1:topspace:Zmax];
contour(F,S,Z,levels);
grid
  댓글 수: 2
Emma Reznick
Emma Reznick 2018년 3월 20일
That works great, thanks! I had to add a line in to remove the infinite terms, but otherwise very helpful!
Here is what I had to add:
Z(isinf(Z)==1)=15
Abraham Boayue
Abraham Boayue 2018년 3월 20일
You are welcome, I glad you well able to come up with a solution.

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

추가 답변 (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