Too many input arguments when reading excel sheet into matlab plot

5 views (last 30 days)
I am having trouble with plotting excel data in matlab.
My excel sheet is rather big, but I only want to plot the columns A(3:301), R(3:301) and Q(3:301). I get an "too many input arguments" error with the following code.
I dont really know how to tell matlab this, can somebody please help?
I get this error:
Warning: Column headers from the file were modified to make them valid
MATLAB identifiers before creating variable names for the table. The
original column headers are saved in the VariableDescriptions property.
Set 'PreserveVariableNames' to true to use the original column headers
as table variable names.
Error using tabular/plot
Too many input arguments.
Error in DataresultsPlot (line 27)
plot(time_data, T_proximal, current_data);
% Pfade zu den Ordnern mit den Excel-Dateien angeben
folder_paths = {
'C:\Users\anhky\Documents\Uni Stuff\Master\Masterarbeit\Evaluation\Data\d_2mm\Experiment 1',
};
% Loop über alle Ordner
for folder_index = 1:length(folder_paths)
folder_path = folder_paths{folder_index};
% Dateien in dem Ordner auflisten
file_list = dir(fullfile(folder_path, '*.xlsx'));
% Loop über alle Dateien in dem Ordner
for file_index = 1:length(file_list)
% Excel-Datei einlesen
file_path = fullfile(folder_path, file_list(file_index).name);
data = readtable(file_path);
% x- und y-Daten extrahieren
time_data = data(3:end, 1); % erste Spalte in Excel
T_proximal = data(3:end, 18); % zweite Spalte in Excel
current_data = data(3:end, 17); % dritte Spalte in Excel
% Graphen plotten
figure; % neues Figure-Fenster öffnen
plot(time_data, T_proximal, current_data);
% Achsenbeschriftungen hinzufügen
xlabel('time');
ylabel('T proximal');
zlabel('current');
% Titel hinzufügen
title(file_list(file_index).name);
% Graphen als PNG-Datei speichern
save_path = fullfile('C:\Pfad\zum\Speicherort', [file_list(file_index).name '.png']);
saveas(gcf, save_path);
end
end
Thanks!

Answers (2)

Cris LaPierre
Cris LaPierre on 13 Mar 2023
Are you trying to create a 3D plot? You are passing 3 inputs (X,Y,Z?) into plot, but plot creates 2D plots.
If instead you want to plot the 3 columns with time being the X value, and the other 2 columns as your Y (so 2 separate dataseries), combine your Y-values into a single array using []. MATLAB treats each column as a unique data series.
% Make up data for this demo
time_data = linspace(0,6*pi)';
T_proximal = sin(time_data);
current_data = cos(2*time_data)/2;
plot(time_data, [T_proximal, current_data]);

Walter Roberson
Walter Roberson on 13 Mar 2023
data = readtable(file_path);
That returns a table() object
% x- und y-Daten extrahieren
time_data = data(3:end, 1); % erste Spalte in Excel
T_proximal = data(3:end, 18); % zweite Spalte in Excel
current_data = data(3:end, 17); % dritte Spalte in Excel
When you use () indexing on a table object, you get out table objects, so time_data and T_proximal and current_data here are all table() objects, each of which has a single variable.
plot(time_data, T_proximal, current_data);
with time_data being a table() object, you are invoking tabular plot rather than regular numeric plot.
plot(TBL,XVAR,YVAR) plots the variables xvar and yvar from the table
tbl. To plot one data set, specify one variable for xvar and one
variable for yvar. To plot multiple data sets, specify multiple
variables for xvar, yvar, or both. If both arguments specify multiple
variables, they must specify the same number of variables
plot(TBL,YVAR) plots the specified variable from the table against the
row indices in the table. If the table is a timetable, the specified
variable is plotted against the row times from the timetable.
You are using the three-input version of plot() so you would have to be passing in a table and indicators for two variables. The indicators must be string array | character vector | cell array | pattern | numeric scalar or vector | logical vector | vartype()
So for example you could
plot(data(3:end), [1], [18 17])
  9 Comments
Walter Roberson
Walter Roberson on 13 Mar 2023
Which MATLAB version are you using? And can you attach a sample data file?

Sign in to comment.

Categories

Find more on Line 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!