how to do logical indexing

2 visualizaciones (últimos 30 días)
Ryaan Semwal
Ryaan Semwal el 24 de Feb. de 2016
Comentada: Ryaan Semwal el 24 de Feb. de 2016
I need to plot a graph for that I have two files velocity and time. But I have to plot the graph for certain interval of time, so can you help me how should I get the corresponding velocity points as both the files are in vector form.
Thanks

Respuesta aceptada

Guillaume
Guillaume el 24 de Feb. de 2016
See Using logicals in array indexing. In your case it's going to be something like:
%time: vector of time
%velocity: vector of velocity
intime = time >= starttime & time <= endtime
plot(time(intime), velocity(intime))
  2 comentarios
Ryaan Semwal
Ryaan Semwal el 24 de Feb. de 2016
Editada: Stephen23 el 24 de Feb. de 2016
Hi,
Thanks for your quick reply. I am new to matlab so I am attaching my script in this comment as I am getting error. I will be thankful to you if you can help me figure out my mistake
Thanks
names = dir('*.smat.mat');
names = {names.name};
for i = 1:length(names)
S = load(names{i});
time_data=S.timezones;
% isfield(S,'timeClean')
whole_time=S.timeClean;
% A=sort(velocity_data);
% % timepoints=whole_time(whole_time(:,1) >= time_data(1,1) & whole_time(:,1) < time_data(2,1));
velocity_data=S.VelClean;
% velocity_index=(velocity_data>time_data(1,1)) & (velocity_data<time_data(1,1))
intime=time>time_data(1,1)& time<=time_data(2,1);
plot(whole_time(intime),velocity_data(intime))
% end
end
Ryaan Semwal
Ryaan Semwal el 24 de Feb. de 2016
hi, Figured out the mistake. Thanks a lot for your help.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by