필터 지우기
필터 지우기

My plot is not showing the lines. Can someone please point me in the right direction? Thanks,

조회 수: 3 (최근 30일)
%clear
%clc
disp('Exotic Llama Enclosure Perimeter Fence Optimization')
disp('_____________________________________________________')
disp('Note - do NOT enter enclosure to take measurements!')
fprintf('\n\n')
disp('The Cost Equation in terms of Area & Radius is given below,')
disp('As solved from the Area and Perimeter Fence Costs equations:')
% Variables
% part 1 - all symbolic versions of variables below
% part 2: R - radius of curve (m), A - Area of enclosure (m^2), Cost_C -
% curved wall cost ($/m), Cost_S - Straight Wall Cost ($/m), FenceCost -
% cost of enclosure fence ($), Rmin - minimum curve radius (m), Rbest -
% radius that minimizes cost (m), Costbest - lowest cost at that Rbest($)
syms Area Cost Radius Length Cost_Curved Cost_Straight
Eq1 = (Area == 2*Radius*Length + pi*Radius^2/2);
Eq1b = solve(Eq1,Length);
Eq2 = (Cost == Cost_Straight*(2*Radius+2*Length)+Cost_Curved*(2*pi*Radius/2));
Eq2b = subs(Eq2, Length, Eq1b)
fprintf('\n')
Cost_S = input('Enter in a cost ($/m) for straight walls : ');
Cost_C = input('Enter in a cost ($/m) for curved wall : ');
Rmin = input('Enter in a minumum enclosure curve Radius (m) : ');
for A = 1000:1000:5000
for R = Rmin:1:50
FenceCost = Cost_S*(2*R + (A - (pi.*R^2)/2)/R) + pi*Cost_C*R;
hold all
plot(R,FenceCost)
xlabel('Radius (meter)')
ylabel('Perimeter Cost ($)')
ytickformat('usd')
title('Perimeter Costs vs Radius at various Floor Areas')
end
end
fprintf('\n\n')
A = input('Enter in a specific Area to determine the Radius to minimize cost (m^2) : ');
myfunction1 = @(R) Cost_S* (2*R + (A-(pi.*R^2)/2)/R)+pi*Cost_C*R;
[Rbest,Costbest] = fminbnd(myfunction1, Rmin, 50);
fprintf('The Radius to minimize cost is: %6.2f (m) at a cost of $%6.2f', Rbest, Costbest)
  댓글 수: 1
Adam
Adam 2019년 7월 29일
편집: Adam 2019년 7월 29일
You should collect up all your results in an array in your for loop and do a single plot at the end. It will be faster and your plot will then have all the data on it, joined by lines. You are just plotting one point at a time and the default behaviour for plot is to use no marker, so plotting a single point with no marker shows nothing. If you want markers then you can look at
doc plot
to see how they are specified, though you should still do it all in one plot because the more individual graphics objects you have the more memory is used and the slower your plot will respond.

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

답변 (1개)

Jalaj Gambhir
Jalaj Gambhir 2019년 8월 1일
Hi,
As pointed out correctly in the comments, the plot won't show anything if you plot a single point without a marker. It is because by default the function connects two points and creates a line. Try:
plot(R,FenceCost,'-o');

카테고리

Help CenterFile Exchange에서 Historical Contests에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by