Error using plot Invalid subscript for Y.

73 views (last 30 days)
I imported data using import data funtion and want plot FO2_Odometer vs 1st sensor ,I keep getting this error please help me
  4 Comments
Rik
Rik on 9 May 2022
Casting to double might be enough. If you had posted your code as code instead of a screenshot I would have done that for you.
Utsav Lakhlani
Utsav Lakhlani on 9 May 2022
%% Import data from text file
% Script for importing data from the following text file:
%
% filename: C:\Users\utsav\OneDrive\Desktop\TIP\Data_set0.csv
%
% Auto-generated by MATLAB on 09-May-2022 15:48:25
%% Set up the Import Options and import the data
opts = delimitedTextImportOptions("NumVariables", 43);
% Specify range and delimiter
opts.DataLines = [3, Inf];
opts.Delimiter = ",";
% Specify column names and types
opts.VariableNames = ["Date", "Time", "Odometer1", "Odometer2", "speed1", "speed2", "impulse", "AccX", "AccY", "AccZ", "PT100", "sys_temp", "DP", "Pressure", "Pitch", "Roll", "FO2_Odometer", "FO2_Speed", "status", "Caliper1", "Caliper2", "Caliper3", "Caliper4", "Caliper5", "Caliper6", "Caliper7", "Caliper8", "Caliper9", "Caliper10", "Caliper11", "Caliper12", "Caliper13", "Caliper14", "Caliper15", "Caliper16", "ID1", "ID2", "ID3", "ID4", "ID5", "ID6", "ID7", "ID8"];
opts.VariableTypes = ["datetime", "datetime", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double"];
% Specify file level properties
opts.ExtraColumnsRule = "ignore";
opts.EmptyLineRule = "read";
% Specify variable properties
opts = setvaropts(opts, "Date", "InputFormat", "dd/MM/yyyy");
opts = setvaropts(opts, "Time", "InputFormat", "HH:mm:ss");
opts = setvaropts(opts, "status", "TrimNonNumeric", true);
opts = setvaropts(opts, "status", "ThousandsSeparator", ",");
% Import the data
Dataset0 = readtable("C:\Users\utsav\OneDrive\Desktop\TIP\Data_set0.csv", opts);
%% Clear temporary variables
clear opts
sensors = Dataset0(:,20:35);
FO2_Odometer = Dataset0(:,17);
plot(FO2_Odometer,sensors(:,1))

Sign in to comment.

Accepted Answer

Rik
Rik on 9 May 2022
Let's generate some data and try my suggestion of casting to double:
%generate data
FO2_Odometer=rand(10,1);Caliper1=rand(10,1);Caliper2=rand(10,1);Caliper3=rand(10,1);
Dataset0=table(FO2_Odometer,Caliper1, Caliper2, Caliper3)
Dataset0 = 10×4 table
FO2_Odometer Caliper1 Caliper2 Caliper3 ____________ ________ ________ ________ 0.69186 0.51453 0.51247 0.87264 0.87827 0.78237 0.81322 0.30298 0.24861 0.70964 0.65119 0.58141 0.032346 0.096039 0.11605 0.40892 0.27076 0.014997 0.003108 0.75369 0.067883 0.45315 0.18844 0.39127 0.49965 0.77489 0.74358 0.78742 0.52503 0.93181 0.83883 0.68599 0.82869 0.99609 0.031551 0.20222 0.62017 0.69801 0.79995 0.20609
% extract the data and try casting to double
sensors = Dataset0(:,2:4);
FO2_Odometer = Dataset0(:,1);
try
double(FO2_Odometer)
catch ME,fprintf('Error using tabular/double\n%s\n',ME.message),end
Error using tabular/double Undefined function 'double' for input arguments of type 'table'. To convert to numeric, use the TABLE2ARRAY function, or extract data using dot or brace subscripting.
Oops. An error. Luckily, it provides a suggestion to extract the data.
Since the error message suggests this, let's try it:
FO2_Odometer=table2array(FO2_Odometer);
sensors=table2array(sensors);
plot(FO2_Odometer,sensors(:,1),'*')

More Answers (0)

Categories

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