MATLAB: How could I fix the script from the comments that were given

functionimporting excel data

Write a function plotData(filename,markers)
  1. Takes an input the filename of an Excel file which contains two columns of numbers and in which the first entry of each column is a string.
  2. Plots a solid line graph in black representing the relation between the columns of numbers in the Excel file. The x-values of the graph should consist of the numbers in the first column, and the y-values of the graph should consist of the numbers in the second column.
  3. If the value of the boolean variable markers is true, the graph should plot an 'o' at each data point.
  4. THe x and y axis of the plot should be labeled using the respective name of the column.
  5. The title of the plot should be the name of the Excel file.
function [xy]= plotData(file,markers)
x=xlsread('data.xlsx','A3:A9'); %this needs to be more general,

%what if you have a file where the input data is located in B4 through B12?
y=xlsread('data.xlsx','B3:B9'); %this needs to be more general,
%what if you have a file where the output data is located in C4 through C12?
[num,txt]=xlsread(filename)
title('data.xlsx') %needs to depend on the input variable called file
xlabel('time(sec)') %needs to depend on what’s in the Excel file
ylabel('height(meters)') %needs to depend on what’s in the Excel file
if markers==true
plot(x,y,'k-o');
else
plot(x,y,'k-');
end

Best Answer

file = 'data.xlsx' ;
[num,txt,raw] = xlsread(file) ;
x = num(:,1) ;
y = num(:,2) ;
figure
hold on
plot(x,y) ;
title(file) ;
xlabel(txt{1}) ;
ylable(txt{2}) ;