

Hello!
I would like to ask for your help on how to open a text file in scilab and placing its elements in an array, so that I can plot the elements and calculate its mean-squared displacement.
The data in the text file looks like this:
===start of file===
3 1 1 17 2 2 14 1 2 3
# and so on...
====end of file====
The data points for the plot look like this: (x-val, y-val) or
[(1,3),(2,1),(3,1),(4,17),(5,2),(6,2),(7,14),(8,1),(9,2),(10,3),...]
where x-val are just counting numbers 1,2,3,4,5,... and y-val are the elements of the input file.
Also, using the same input file, the mean-squared displacement is calculated like this (matlab code):
===start of matlab codes===
nData = size(data,1); %# number of data points
numberOfdeltaT = floor(nData/4); %# for MSD, dt should be up to 1/4 of number of data points
msd = zeros(numberOfDeltaT,3); %# We'll store [mean, std, n]
%# calculate msd for all deltaT's
for dt = 1:numberOfDeltaT
deltaCoords = data(1+dt:end,2:4) - data(1:end-dt,2:4);
squaredDisplacement = sum(deltaCoords.^2,2); %# dx^2+dy^2+dz^2
msd(dt,1) = mean(squaredDisplacement); %# average
msd(dt,2) = std(squaredDisplacement); %# std
msd(dt,3) = length(squaredDisplacement); %# n
end
====endof matlab codes====
Given this code, how do we plot msd (y-axis) vs deltaT (x-axis)?
I appreciate all your help. Thank you!
Scilab


Code given below will help you to understand how to import numerical values from a .txt file.
clc;
clear;
a=read('test.txt',-1,1) //read the numbers from .txt file
b=0:length(a);
c=length(a)//length of x and y axes
for i=1:c
x(i)=b(i)+1;
for j=1:c
y(j)=a(j);
end
end
points = list([x y]);
disp(points, "Points are :");
xtitle("Graph name","X-axis", "Y-axis");
plot(x,y);
By using these points, you can calculate the value of MSD further.
Login to add comment