Inverse index problem.

조회 수: 17 (최근 30일)
Nedim Hodzic
Nedim Hodzic 2016년 5월 28일
댓글: Nedim Hodzic 2016년 5월 28일
Shortly, I have a sensor that logs the data and some values. In this example I process only temperature and time. What I wanted to do is to make an index which will filter through occupancy hours, so I pick just data when I define someone is in this room. The problem for me comes when I have to select the index interval. Here is the simplification of code and I'll explain what exactly is causing trouble:
time_sensor = datenum(sensor.textdata);
temperature = sensor.data(:,3);
timevec = datevec(time_sensor);
ind_occ = timevec(:,4)>9 & timevec(:,4)<16;
ind_occ = (1 - ind_occ);
Here comes the problem; I basically want to exclude the time from 9 to 16h, therefore I made the index for that period and the idea was to just inverse that matrix with this line. If I comment it out, the plot runs with no problems. With this it returns an error and no plot: (Subscript indices must either be real positive integers or logicals. Error in example (line 34) plot(time_sensor(ind_occ,:),temperature(ind_occ,:));)
mintime=time_sensor(1,1);
maxtime=time_sensor(end,1);
figure (1)
plot(time_sensor(ind_occ,:),temperature(ind_occ,:));
axis([mintime,maxtime,12,25]);
datetick('x',1,'keeplimits','keepticks')
title(sprintf('max: %0.1f | min: %0.1f | average: %0.1f',max(temperature(ind_occ,:)),min(temperature(ind_occ,:)),mean(temperature(ind_occ,:))));
ylabel('Temperature');
Thanks for the help. I am very very new to Matlab, so sorry if I made some rookie mistake!

채택된 답변

Stephen23
Stephen23 2016년 5월 28일
편집: Stephen23 2016년 5월 28일
You can create the logical inverse by using a logical not ~:
ind_occ = ~ind_occ;
or
ind_occ = ~(timevec(:,4)>9 & timevec(:,4)<16);
And using this wherever you currently use ind_occ. Or alternatively you can simply invert the comparisons:
ind_occ = timevec(:,4)<= | timevec(:,4)>=16;
Note that in both cases you do not need this line, so delete it:
ind_occ = (1 - ind_occ);
  댓글 수: 1
Nedim Hodzic
Nedim Hodzic 2016년 5월 28일
Thank you very much!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by