So we don't need to plot the graph?
That is correct. The problem description is one thing. The test suite is another. The test suite explicitly accommodates solutions that do not plot the graph. Since this took extra effort to incorporate into the test suite, I view my solution as fully within the scope and intent of this problem.
Test | Status | Code Input and Output |
---|---|---|
1 | Fail |
clf;
t = linspace(0,15,400);
y = exp(-0.5*t).*cos(2*pi.*t);
m = plot_cos(y, t);
assert(abs(m - (-0.781239288889930)) <= 1e-4)
h = findobj(gcf, 'Type', 'Line');
if length(h) == 2
assert(isequal([h.Color], [1 0 0 0 0 1]), 'Check plot colors')
assert(strcmp([h.LineStyle], 'none--'), 'Check the line style')
assert(strcmp([h.Marker],'*none'), 'Check marker type')
assert(isequal([h.YData],[m, y]), 'Check plotted data')
elseif length(h) == 1
assert(isequal([h.Color], [0 0 1]),'Check plot colors')
assert(strcmp([h.LineStyle], '--'), 'Check the line style')
assert(strcmp([h.Marker],'*'),'Check marker type')
assert(isequal([h.YData],y),'Check plotted data' )
assert(isequal([h.MarkerEdgeColor], [1 0 0]),'Check plot colors')
assert(isequal([h.MarkerIndices], 14),'Check marker location')
elseif length(h)>2
error('There may be too many plots on the figure.')
else
error('No plot found.')
end
|
2 | Fail |
clf;
t = linspace(2,5,100);
y = exp(-0.5*t).*cos(2*pi.*t);
m = plot_cos(y, t);
assert(abs(m - (-0.287376348726584)) <= 1e-4)
h = findobj(gcf, 'Type', 'Line');
if length(h) == 2
assert(isequal([h.Color], [1 0 0 0 0 1]), 'Check plot colors')
assert(strcmp([h.LineStyle], 'none--'), 'Check the line style')
assert(strcmp([h.Marker],'*none'), 'Check marker type')
assert(isequal([h.YData],[m, y]), 'Check plotted data')
elseif length(h) == 1
assert(isequal([h.Color], [0 0 1]),'Check plot colors')
assert(strcmp([h.LineStyle], '--'), 'Check the line style')
assert(strcmp([h.Marker],'*'),'Check marker type')
assert(isequal([h.YData],y),'Check plotted data' )
assert(isequal([h.MarkerEdgeColor], [1 0 0]),'Check plot colors')
assert(isequal([h.MarkerIndices],17 ),'Check marker location')
elseif length(h)>2
error('There may be too many plots on the figure.')
else
error('No plot found.')
end
|
Omit columns averages from a matrix
527 Solvers
2810 Solvers
Side of an equilateral triangle
2595 Solvers
202 Solvers
353 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!