Error in plot function

1 view (last 30 days)
Hassan Ashraf
Hassan Ashraf on 19 Sep 2019
Commented: Hassan Ashraf on 20 Sep 2019
Hi I am plotting some results but getting an error in Plot Function. I am using MATLAB 2018b, below is my code
load MCAsLDA
MCAsLDA = table2array(MCAsLDA);
WindowSizes=MCAsLDA(:,1);
Data1Disjoint=MCAsLDA(:,2);
% Data1Disjoint=smooth(Data1Disjoint);
Data1Overlap=MCAsLDA(:,3);
% Data1Overlap=smooth(Data1Overlap);
Data2Disjoint=MCAsLDA(:,4);
% Data2Disjoint=smooth(Data2Disjoint);
Data2Overlap=MCAsLDA(:,5);
% Data2Overlap=smooth(Data2Overlap);
Data3Disjoint=MCAsLDA(:,6);
% Data3Disjoint=smooth(Data3Disjoint);
Data3Overlap=MCAsLDA(:,7);
f1=fit(WindowSizes,Data1Disjoint,'cubicinterp');
f2=fit(WindowSizes,Data2Disjoint,'cubicinterp');
f3=fit(WindowSizes,Data3Disjoint,'cubicinterp');
f4=fit(WindowSizes,Data1Overlap,'cubicinterp');
f5=fit(WindowSizes,Data2Overlap,'cubicinterp');
f6=fit(WindowSizes,Data3Overlap,'cubicinterp');
figure
hold on
p1=plot(f1,WindowSizes,Data1Disjoint,'LineWidth',2);
p2=plot(f2,WindowSizes,Data2Disjoint);
p3=plot(f3,WindowSizes,Data3Disjoint);
p4=plot(f4,WindowSizes,Data1Overlap);
p5=plot(f5,WindowSizes,Data2Overlap);
p6=plot(f6,WindowSizes,Data3Overlap);
grid on
title('Classification accuracy Vs. Window Sizes for LDA')
ylabel('Mean Classification Accuracy')
  1 Comment
Adam Danz
Adam Danz on 19 Sep 2019
Always specify the entire error message.
The logical indices contain a true value outside of the
array bounds.
Error in cfit/plot (line 226)
handles =
plot(xpoints(~outliers),ypoints(~outliers),S2,...
Error in jff (line 26)
p1=plot(f1,[WindowSizes,Data1Disjoint],'LineWidth',2);

Sign in to comment.

Accepted Answer

Adam Danz
Adam Danz on 19 Sep 2019
Edited: Adam Danz on 19 Sep 2019
Remove the 'LineWidth' name-value pair and specify it after plotting.
p1=plot(f1,WindowSizes,Data1Disjoint);
set(p1,'LineWidth', 2, 'MarkerSize', 25)
If you want to change the properties for all objects,
p(1,:)=plot(f1,WindowSizes,Data1Disjoint);
p(2,:)=plot(f2,WindowSizes,Data2Disjoint);
p(3,:)=plot(f3,WindowSizes,Data3Disjoint);
p(4,:)=plot(f4,WindowSizes,Data1Overlap);
p(5,:)=plot(f5,WindowSizes,Data2Overlap);
p(6,:)=plot(f6,WindowSizes,Data3Overlap);
set(p, 'LineWidth', 2, 'MarkerSize', 20)
Set different colors for each line
set(p(:,2), {'Color'}, mat2cell(jet(size(p,1)),ones(size(p,1),1),3))
Clean up the legend
set(p(:,2), {'DisplayName'}, strcat('fit #',strsplit(num2str(1:size(p,1))))')
legend(p(:,2))
Final result
190919 084706-Figure 1.png

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by