Why do I get the error "Invalid or deleted object" for this code
Afficher commentaires plus anciens
I have the code below which I have run before without problems but I suddenly get the error message "Error using stackedplot (line 100)
Invalid or deleted object." at the line "stackedplot(acctable,{'accX','accY','accZ'})". Can anyone help with this?
file = ('F:\MATLAB\Vessel_data\Galloper\Seacat Liberty\improveddata2019-09-30');
load (file)
%Create table of two columns time and acceleration
if isfield(data,'COM23_heading')== 1
full_trip = table(data.timeStamp,data.accX,data.accY,data.accZ,data.roll,data.pitch,data.yaw,data.COM23_speed,data.COM23_heading,data.COM23_lat,data.COM23_lon,data.dist2harbour,data.dist2turbine,data.inField,'VariableNames',{'timeStamp','accX[G]','accY[G]','accZ[G]','roll[deg]','pitch[deg]','yaw[deg]','speed[kph]','heading[deg]','lat','lon','dist2harbour','dist2turbine','inField'});
else
full_trip = table(data.timeStamp,data.accX,data.accY,data.accZ,data.roll,data.pitch,data.yaw,data.COM7_speed,data.COM7_heading,data.COM7_lat,data.COM7_lon,data.dist2harbour,data.dist2turbine,data.inField,'VariableNames',{'timeStamp','accX[G]','accY[G]','accZ[G]','roll[deg]','pitch[deg]','yaw[deg]','speed[kph]','heading[deg]','lat','lon','dist2harbour','dist2turbine','inField'});
end
%Convert timestamp to datenum format
full_trip.date = datetime(full_trip.timeStamp,'ConvertFrom',"datenum");
%Create time/durtion in second by converting datetime to seconds
durtime = datetime(full_trip.date, 'InputFormat', 'yyyy-MM-dd HH:mm:ss.SS', 'Format', 'yyyy-MM-dd HH:mm:ss.SS');
durtime(isnat(durtime)) = datetime(full_trip.date(isnat(durtime)), 'InputFormat', 'yyyy-MM-dd HH:mm:ss');
full_trip.date = durtime;
full_trip.duration = seconds(full_trip.date - full_trip.date(1));
%convert acc in G to m/s^2
full_trip.accX = convacc(full_trip.("accX[G]"),'G''s','m/s^2');
full_trip.accY = convacc(full_trip.("accY[G]"),'G''s','m/s^2');
full_trip.accZ = convacc(full_trip.("accZ[G]"),'G''s','m/s^2');
%Rearrange and remove timestamp variable
full_trip = movevars(full_trip, {'date','duration','accX','accY','accZ'}, 'Before', "accX[G]");
%Create a categorial value of in windfarm
full_trip.location = categorical(full_trip.inField);
full_trip.location = renamecats(full_trip.location,"false","Transit");
full_trip.location = renamecats(full_trip.location,"true","Windfarm");
Visualize data
acctable = table(full_trip.duration,full_trip.date,full_trip.accX,full_trip.accY,full_trip.accZ,'VariableNames',{'duration','date','accX','accY','accZ'});
acctimetable = table2timetable(acctable);
windowlength = 1800;
stdaccY = retime(acctimetable,"regular",@std,"TimeStep",seconds(windowlength));
figure(1)
subplot(3,2,[1,2])
geoplot(full_trip.lat,full_trip.lon)
subplot(3,2,3)
stackedplot(acctable,{'accX','accY','accZ'})
subplot(3,2,4)
plot(stdaccY.date(1:end-1),stdaccY{1:end-1,["accX","accY","accZ"]},'o-')
ylabel("Std value from sensor")
legend(["X","Y","Z"],"Location","northeast")
title(compose("Vessel Acceleration: ""std"" method, %.1f seconds per window",windowlength))
subplot(3,2,5)
stackedplot(full_trip,{'roll[deg]','pitch[deg]'})
subplot(3,2,6)
gscatter(full_trip.date,full_trip.(13),full_trip.location)
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Data Type Conversion dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!