How to display two similar functions on a graph?

3 次查看(过去 30 天)
Hello there. I am having a bit of confusion with some code that I made, and I just need some clarification.
So I made a function here, designed to sort random numbers from an array:
function[out] = bubbleSort(a)
a = input('Enter an array of numbers to sort: ');
x = rand(1,a);
nvals = length(x);
for ii = 1:nvals-1
iptr = ii;
for jj = ii+1:nvals
if x(jj) < x(iptr)
iptr = jj;
end
end
if ii ~= iptr
temp = x(ii);
x(ii) = x(iptr);
x(iptr) = temp;
end
end
out = x;
disp(out)
And I made a call out script that utilizes the standard 'sort' function in MATLAB, and the objective is to plot the two sorts into a logarithmic plot like so:
clc
clear
a = input('Enter the array of numbers to sort: ');
x = rand(1,a);
matlabsorter = sort(x);
semilogx(matlabsorter)
hold on
semilogx(bubbleSort)
grid on
ylabel('Array Size')
xlabel('Elapsed Time')
legend('matlabsorter','bubbleSort')
hold on
The thing is however, when this executes, the two plots look identical and I'm not so sure it that's how it's supposed to be. Could anyone give any input on this?

采纳的回答

Roger Stafford
Roger Stafford 2017-10-27
You could use different 'linespecs' in the plots, say 'y0' on one and 'r*' on the other. If the two sort results are the same, the asterisks should be centered inside the circles.
  2 个评论
Matt Amador
Matt Amador 2017-10-27
I'm not sure what you mean. Can you show an example of what you are trying to say?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by