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 Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by