MATLAB Answers

Create plot of object movement

3 views (last 30 days)
Stefania Cionca
Stefania Cionca on 10 Dec 2019
Commented: Mario Malic on 10 Dec 2019
I am an absolute beginner when it comes to Matlab, I installed it yesterday, so I am very sorry if I sound ignorant about it.
Here's my problem: I have some csv files with vector coordinates and I want to create plots for the movement of an object. I have multiple of these csv files and I want a separate figure for each of them. The coordinates of the object change every few seconds (or fractions of a second) so the plot should make this visible. I received this script from someone that previously used it without any problems (at least to my knowledge).
The errors I am currently getting are regarding sm_time and sm_distance that apparently are not defined. The problem is that I have no idea what they're supposed to refer to.
% current folder & files
% provide inputfolder!!
folderIn='C:\S001';
d = dir(fullfile(folderIn, '*.csv')); % every .xlsx is detected
files = {d.name};
for k=1:numel(files)
name = files{k};
% % Reading in data into matrix M, starting at row 2 and coloumn 0
M = readmatrix(string(A));
% %%%%%%%%%%%%%%%%% Time-Analysis using time-stamp %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% calculating time
t=M(:,1);% reading data for time-analysis, coloumn 1
b=t(end,:);
a=t(1,1);
time= sm_time(a,b); % call funtion T
x=M(:,2); y=M(:,3);
distance_traveled=0;% start-initiation
for i=1:slx
distance_traveled=distance_traveled+sum(sm_distance(x(i),x(i+1),y(i),y(i+1)));% cumulative distance traveled
end
% calculating VELOCITY
velocity= distance_traveled/time;
figure
plot(x,y)
end
I don't expect anyone to tell me the perfect solution, but maybe someone could explain to me what exactly this part is trying to do and if there's a way around it?
t=M(:,1);% reading data for time-analysis, coloumn 1
b=t(end,:);
a=t(1,1);
time= sm_time(a,b); % call funtion T
x=M(:,2); y=M(:,3);
distance_traveled=0;% start-initiation
for i=1:slx
distance_traveled=distance_traveled+sum(sm_distance(x(i),x(i+1),y(i),y(i+1)));% cumulative distance traveled
end
Thank you in advance!

  1 Comment

Mario Malic
Mario Malic on 10 Dec 2019
Hi Stefania,
% % Reading in data into matrix M, starting at row 2 and coloumn 0
M = readmatrix(string(A)); % Reads data from Excel files, not sure if it reads according to comment above
t=M(:,1);% reads first column from M and saves it at t
b=t(end,:); % reads last row from t (previous command saved only one column, so this will be a single value)
a=t(1,1); % reads value of t at indices 1,1
time= sm_time(a,b); % call funtion T
You should check what inputs does the function sm_time require, and according to that make changes to your code.
If it previously worked, then maybe you did not adjust folder name.

Sign in to comment.

Answers (0)

Sign in to answer this question.

Products