Animation plot with parameter
4 次查看(过去 30 天)
显示 更早的评论
I'm workong at a university project in which there is the simulation (mock-test) of a train moves on a platform at a certain distance. Once a vector (media) is uploaded from excel with some parameters to take into account, checking follows.In matlab i'm neophyte
A second graph, with the train icon to be simulated and the straight line with points is uploaded (plot2). If check of parameter is ok the points change into green, this means that the checking of parameters given is included within a certain range in the average vector. If the pointschange into red this means that the train it will stop This process to show that the train moves within a certain average so in every point of the plot on the train icon, the checking of the parameter i the average vector must be done. If the checking is positive, the icon will be green, otherwise it will be red and the train must be stopped for a given time,but this process should be automated .in the end I have to find the total travel time from 0 to 80 km . Thanks for your help , i need advice .
function [Media] = importfile(workbookFile, sheetName, dataLines)
%IMPORTFILE Import data from a spreadsheet
% If no sheet is specified, read first sheet
if nargin == 1 || isempty(sheetName)
sheetName = 1;
end
% If row start and end points are not specified, define defaults
if nargin <= 2
dataLines = [1, 82];
end
%% Setup the Import Options and import the data
opts = spreadsheetImportOptions("NumVariables", 1);
% Specify sheet and range
opts.Sheet = sheetName;
opts.DataRange = "F" + dataLines(1, 1) + ":F" + dataLines(1, 2);
% Specify column names and types
opts.VariableNames = "Media";
opts.VariableTypes = "double";
% Specify variable properties
opts = setvaropts(opts, "Media", "FillValue", 65.4);
% Import the data
tbl = readtable(workbookFile, opts, "UseExcel", false);
for idx = 2:size(dataLines, 1)
opts.DataRange = "F" + dataLines(idx, 1) + ":F" + dataLines(idx, 2);
tb = readtable(workbookFile, opts, "UseExcel", false);
tbl = [tbl; tb]; %#ok<AGROW>
end
%% Convert to output type
Media = tbl.Media;
%%SET VELOCITY KM/H
for i=Media
if Media[i]==0
mA=false;
pR=false;
%%RED POINT AND STOPPING TRAIN FOR 30SEC
else
mA=true;
pr=true;
%%TRAIN ANIMATION ON PLOT GREEN POINT FOR 1 POINT ON PLOT
end
%journey time calculation
%%openfig('matlabgrafico.fig',h(1));
%%fprintf('%d',Media);
figure
plot((0:100).^0)
axes('pos',[0.2 0.2 0.1 .1]);
imshow('immagine treno.png')
openfig('matlabgrafico.fig');
end
0 个评论
采纳的回答
Navya Seelam
2020-3-30
You can use animatedline to update the graph as per the required parameter. Below is the code that updates the graph with the parameter 'k'. Refer to the link below for more details.
h = animatedline('Marker','o',...
'LineWidth',2,...
'MarkerSize',10,...
'MarkerEdgeColor','none',...
'MarkerFaceColor',[0,0.5,0],'LineStyle','none');
h1 = animatedline('Marker','o',...
'LineWidth',2,...
'MarkerSize',10,...
'MarkerEdgeColor','none',...
'MarkerFaceColor',[0.5,0,0],'LineStyle','none');
axis([0 4*pi -1 1])
x = linspace(0,4*pi,100);
for k = 1:length(x)
if mod(k,11)
y = sin(x(k));
addpoints(h,x(k),y);
drawnow
hold on
else
y = sin(x(k));
addpoints(h1,x(k),y);
drawnow
end
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!