Please help this semilogy error message
이전 댓글 표시
can you tell me what is wrong with this line ؟
it says
Error using semilogy
Not enough input arguments.
semilogy (BestCost(1,:),
'LineWidth',2,'Color','r',BestCost(2,:),'LineWidth',2,'Color','b')
figure;
semilogy (BestCost(1,:), 'LineWidth',2,'Color','r',BestCost(2,:),'LineWidth',2,'Color','b')
xlabel('Iteration');
ylabel('Best Cost');
legend('normal','stop and watch')
grid on;
hold on
thank you
댓글 수: 5
dpb
2023년 5월 15일
Implicit x values are accepted for only one y argument; the multiple triplets form works for only x,y pairs.
hL=semilogy (BestCost(1:2,:).', 'LineWidth',2)
should work to do the same thing using the builtin feature to plot arrays by column.
ahmed mer
2023년 5월 15일
It shows one line because it assumes that ‘BestCost(1,:)’ are the ‘x’ ccordinates and ‘BestCost(2,:)’ are the ‘y’ coordinates.
To plot both as individual plots, try something like this —
BestCost = [rand(1,10); rand(1,10)];
figure;
semilogy(BestCost(1,:), 'LineWidth',2,'Color','r')
hold on
plot(BestCost(2,:),'LineWidth',2,'Color','b')
hold off
xlabel('Iteration');
ylabel('Best Cost');
legend('normal','stop and watch')
grid on;
hold on
The second plot inherits the axes of the first plot, so they will both appear on semilogy axes.
.
BestCost = [rand(1,10); rand(1,10)];
semilogy(BestCost.','linewidth',2)
xlabel('Iteration');
ylabel('Best Cost');
legend('normal','stop and watch')
grid on;
Don't need explicit x nor to plot each individually -- the one argument as a 2-column array uses the builtin interpretation by plot and friends to treat columns as separate variables; it rotates through the default colormap automagically, too.
Walter Roberson
2023년 5월 15일
편집: Walter Roberson
2023년 5월 15일
semilogy (BestCost(1,:), 'LineWidth',2,'Color','r',BestCost(2,:),'LineWidth',2,'Color','b')
In the plotting functions, once you have start the first name/value pair, everything else on the line must be name/value pairs.
The plotting functions do not permit adding name/value pairs for each distinct set of data: the name/value pairs must go after all data specifications, and the name/value pairs will apply to all sets of data in the same call.
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

