how to do logical indexing

2 vues (au cours des 30 derniers jours)
Ryaan Semwal
Ryaan Semwal le 24 Fév 2016
Commenté : Ryaan Semwal le 24 Fév 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

Réponse acceptée

Guillaume
Guillaume le 24 Fév 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 commentaires
Ryaan Semwal
Ryaan Semwal le 24 Fév 2016
Modifié(e) : Stephen23 le 24 Fév 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 le 24 Fév 2016
hi, Figured out the mistake. Thanks a lot for your help.

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by