My script is not giving me the title, xlabel, and ylabel that I am asking so how can I fix it?

6 vues (au cours des 30 derniers jours)
function [xy]= plotData(filename,markers)
%data=xlsread('data.xlsx');
[num,txt]=xlsread(filename);
x=num(:,1);
y=num(:,2);
title(filename)
xlabel(txt{1})
ylabel(txt{2})
if markers==true
plot(x,y,'k-o');
else
plot(x,y,'k-');
end
  2 commentaires
madhan ravi
madhan ravi le 28 Nov 2018
upload your file and what is markers? provide its data too
Geoff Hayes
Geoff Hayes le 28 Nov 2018
Michael - this looks like very similar code to the homework assignment found at https://www.mathworks.com/matlabcentral/answers/431909-for-an-assignment-i-need-to-create-a-function-that-creates-a-graph-using-data-from-an-imported-excel. Try stepping through the code with the MATLAB debugger to trouble-shoot what is going wrong.

Connectez-vous pour commenter.

Réponse acceptée

Steven Lord
Steven Lord le 28 Nov 2018
Call title, xlabel, and ylabel after calling plot. By default calling plot is going to clear graphics objects from the axes, reset most axes properties to their default values, and calculate new axes limits as stated on this documentation page.

Plus de réponses (0)

Catégories

En savoir plus sur Data Import from MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by