Loop code for many data files and save
    4 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Tesla
 el 20 de Jul. de 2021
  
    
    
    
    
    Comentada: Tesla
 el 21 de Jul. de 2021
            I wrote this code, which load a file text2.dat, to use its data to calculate velocity.
I have many files text3.dat test4.dat...
I want to make this code to load all files and calculate velocity for each file, then save it separatly (vel1.dat, vel2.dat, vel3.dat....)
data=load('test2.dat');
time= data(:,1);
x= data(:,2);
y= data(:,3);
x=x*(3e-7);
y=y*(3e-7);
Vx = gradient(x, time);
Vy = gradient(y, time);
for i=1:n-1
   vel_x(i) = ((x(i)-x(i+1)))/(time(i)-time(i+1));
   %t(i)= x(i)-x(i+1);
   %s= gradient (x);
   vel_y(i) = ((y(i)-y(i+1)))/(time(i)-time(i+1));
   vel(i)   = sqrt(vel_x(i)*vel_x(i)+ vel_y(i)* vel_y(i))
   V(i)  = sqrt(Vx(i)^2 + Vy(i)^2); 
end
%V=V';
indices = find(abs(vel)>2e-4);
vel(indices) = [];
V=V';
0 comentarios
Respuesta aceptada
  Walter Roberson
      
      
 el 20 de Jul. de 2021
        6 comentarios
  Walter Roberson
      
      
 el 21 de Jul. de 2021
				You are deleting some of the vel entries. Remember to delete the corresponding time entries.
You should probably make a variable that has time in the first column and vel in the second column, and save that.
Más respuestas (0)
Ver también
Categorías
				Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

