Azzera filtri
Azzera filtri

How to get rid of error: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table.

14 visualizzazioni (ultimi 30 giorni)
Hello. Would someone please be able to assist with the below.
I have used an Excel sheet that consits of the columns Time, MEngine and MEMotorR which has been attached.
I have generated the following code:
clear; close all;
P = 'C:\Users\m.saeed\Documents\P17R Test Cycles';
T = readtable('Autobahn Comfort Matlab.xlsx','PreserveVariableNames',true);
%% Use for plotting AutoBahn Comfort
T = readtable(fullfile(P,'Autobahn Comfort Matlab.xlsx'),'Sheet','Autobahn Comfort');
%% Plot #5 for Engine Torque (MEngine against Time)
figure ; plot (T.Time,T.MEngine, 'LineWidth',0.80)
xlabel('Time (s)'); ylabel('Engine Torque (Nm))')
ylim([-220 1200]); yticks(-220:142:1200)
legend('MEngine', 'Location', 'best')
title ('Engine Torque vs Time')
exportgraphics(gcf, 'Plot #5 for Engine Torque.png','Resolution',300)
%How many seconds is the engine torque in the following conditions?
T = readtable('Autobahn Comfort.xlsx');
T.MEngine;
V = -220:142:1200;
C = histcounts(T.MEngine,V) * 0.01;
Interval_Of_Torque_Nm = V(:);
Duration_Of_Torque_s = [C(:);NaN];
Engine_Torque = table(Interval_Of_Torque_Nm, Duration_Of_Torque_s, 'VariableNames',{'Interval of Engine Torque (Nm)','Duration of Engine Torque (s)'})
figure ; histogram(T.MEngine,V);
xlabel('Engine Torque (Nm)')
legend('Time (s)', 'Location', 'best')
title ('Duration of Engine Torque')
exportgraphics(gcf, 'Histogram #7 for Duration of Engine Torque.png','Resolution',300)
%
%% Plot #6 for Motor Torque (MEMotorR against Time)
figure ; plot (T.Time,T.MEMotorR, 'LineWidth',0.80)
xlabel('Time (s)'); ylabel('MEMotorR (Nm))')
yline(200, '--r', 'Motor torque limit of 200Nm'); yline(-200, '--r', 'Motor torque limit of -200Nm')
ylim([-220 220]); yticks(-220:40:220)
legend('MEMotorR', 'Location', 'best')
title ('Motor Torque vs Time')
exportgraphics(gcf, 'Plot #6 for Motor Torque.png','Resolution',300)
%How many seconds is the motor torque in the following conditions?
T = readtable('Autobahn Comfort.xlsx');
T.MEMotorR;
V = -220:40:220;
C = histcounts(T.MEMotorR,V) * 0.01;
Interval_Of_Torque_Nm = V(:);
Duration_Of_Torque_s = [C(:);NaN];
Motor_Torque = table(Interval_Of_Torque_Nm, Duration_Of_Torque_s, 'VariableNames',{'Interval of Motor Torque (Nm)','Duration of Motor Torque (s)'})
figure ; histogram(T.MEMotorR,V);
xlabel('Motor Torque (Nm)') % The histogram function automatically chooses an appropriate number of bins to cover the range of values in y
legend('Time (s)', 'Location', 'best')
title ('Duration of Motor Torque')
exportgraphics(gcf, 'Histogram #8 for Duration of Motor Torque.png','Resolution',300)
%
For ex. the graph on the right has some additional horizontal blue line running in the middle (this is not supposed to be there) whilst the one on the left is perfectly fine. I am not sure how this has happened as I have not changed anything in the data of the Excel sheet and neither have I changed any of the code for the plot commmand. Im not sure how to fix the plot.
This is the warning I receive in the workspace but not sure what it entirely means as I have added an initial line of code that preserves the variables.
Would someone please be able to assist with this? Any help will be highly appreciated.
  1 Commento
Stephen23
Stephen23 il 9 Ago 2023
Modificato: Stephen23 il 9 Ago 2023
"How to get rid of error"
That is not an error. It is a warning (as it clearly states). If your code works you can ignore it.
Note: errors are all red text, usually start with "Error...", and mean that code execution stops. In contrast a warning provides information that the user should probably consider, but it does not stop execution.
"I have added an initial line of code that preserves the variables."
You only added it to one READTABLE call, but you call READTABLE twice.

Accedi per commentare.

Risposte (2)

Walter Roberson
Walter Roberson il 9 Ago 2023
T = readtable('Autobahn Comfort.xlsx', 'VariableNamingRule', 'Preserve');

Image Analyst
Image Analyst il 9 Ago 2023
See attached function. Follow instructions in the comments to get the identifier of the error(s) you want to suppress and add them in. I call this in my startup.m file so the warning suppressions apply for all of the m-files I run.
  2 Commenti
Mahnoor
Mahnoor il 9 Ago 2023
Thankyou @Image Analyst,
I would like to fix the error not just get rid of it and fix the data of my plot. Any suggestions on how to do this?
Thankyou.
Image Analyst
Image Analyst il 9 Ago 2023
This line:
T = readtable(fullfile(P,'Autobahn Comfort Matlab.xlsx'),'Sheet','Autobahn Comfort');
"Autobahn Comfort Matlab.xlsx' does not have a sheet called 'Autobahn Comfort'. Rename the sheet.
Also, you did not provide the workbook called "Autobahn Comfort.xlsx".
To get rid of the warning, get rid of the spaces in your column headers in Excel. Make the spaces into underlines.

Accedi per commentare.

Categorie

Scopri di più su Get Started with MATLAB in Help Center e File Exchange

Prodotti


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by