how to do logical indexing

2 views (last 30 days)
Ryaan Semwal
Ryaan Semwal on 24 Feb 2016
Commented: Ryaan Semwal on 24 Feb 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

Accepted Answer

Guillaume
Guillaume on 24 Feb 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 Comments
Ryaan Semwal
Ryaan Semwal on 24 Feb 2016
Edited: Stephen23 on 24 Feb 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 on 24 Feb 2016
hi, Figured out the mistake. Thanks a lot for your help.

Sign in to comment.

More Answers (0)

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!