how to do logical indexing

2 Ansichten (letzte 30 Tage)
Ryaan Semwal
Ryaan Semwal am 24 Feb. 2016
Kommentiert: Ryaan Semwal am 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

Akzeptierte Antwort

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Noch keine Tags eingegeben.

Community Treasure Hunt

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

Start Hunting!

Translated by