How to plot line on graph

1 view (last 30 days)
Kong on 10 Apr 2020
Commented: Star Strider on 11 Apr 2020
Hello. I want to plot a curve line.
When I used this, I got the graph.
I want to plot a red curve line without a blue stick. Could I get an idea to fix this code?
for i = 2:30:750
X = csvread('kth_hog2_only.csv');
Y = csvread('kth_hog2_only_class.csv');
X = X(:,1:i);
Mdl = fitcknn(X,Y,'NumNeighbors',3,...
rng(1); % For reproducibility
CVKNNMdl = crossval(Mdl, 'KFold', 5);
classAccuracy(i) = 100 - kfoldLoss(CVKNNMdl, 'LossFun', 'ClassifError')*100;
xlabel('Number of Clusters')
ylabel('CV Sum of Squared Distances')

Accepted Answer

Star Strider
Star Strider on 10 Apr 2020
Without your data, providing exact code is not possible.
In the interim, try this:
[pks,locs] = findpeaks(classAccuracy);
plot(locs, pks, '-r')
or this:
L = islocalmax(classAccuracy);
x = 1:numel(classAccuracy);
plot(x(L), classAccuracy(L), '-r')
Both should give the same result.
Star Strider
Star Strider on 11 Apr 2020
As always, my pleasure!

Sign in to comment.

More Answers (0)


Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!