フィルターのクリア

Remove cell array rows based on logical condition?

15 ビュー (過去 30 日間)
Erin Winkler
Erin Winkler 2018 年 7 月 18 日
コメント済み: Erin Winkler 2018 年 7 月 19 日
Howdy,
I have a 2267x23 cell array (raw). I would like to remove rows based on the condition of a logical.
Here is what I've done:
I = num(:,20) == 1 | num(:,20) == 7; % Makes logical index for weekend (1 = weekend, 0 = weekday)
E = [num, I];
E(E(:,22) == 0, :) = []; % Weekend bin, site 0
Y = [num, I];
Y(Y(:,22) == 1, :) = []; % Weekday bin, site 0
but I realized that that didn't help me with the raw data. So I want to do something similar to the raw data so I can then have two subsets of cell arrays (Weekend and weekday) but I can't figure it out.
I tried:
E = [raw, I];
E(E(:,24) == 0, :) = [];
.
.
.
but it does not like the concatenating attempt. So I tried making the logical a cell but it does not like that either.
Any help would be stellar, thank you!

採用された回答

OCDER
OCDER 2018 年 7 月 18 日
[Num, ~, Raw] = xlsread('yourdata.xlsx');
I = Num(:,20) == 1 | Num(:,20) == 7; %Your logical index of weekends
Weekend = Raw( I, :);
Weekday = Raw(~I, :);
  3 件のコメント
Erin Winkler
Erin Winkler 2018 年 7 月 19 日
So I've implemented what you've done here and, at first, I thought it worked perfectly. But, upon closer inspection, I realized, it wasn't working at all.
When I run the index I (to split 1 and 7 from 2-6), I does not pick up all of the values that should return a 1. It returns 73 but I know there should be 851. I've gone into the arrays manually and I can see that it's not working properly.
What is wrong with the above that causes the index to not collect all of the correct values?
Erin Winkler
Erin Winkler 2018 年 7 月 19 日
Never mind, I'm dumb. It works :P
Hail Nimrod!

サインインしてコメントする。

その他の回答 (1 件)

dpb
dpb 2018 年 7 月 18 日
With what you've got, you're just looking for
raw(I,:)=[];
to leave week weekday rows of all the data.
Knowing the actual data format in the raw array it might be possible to simplify the machinations done to have gotten to your I
  2 件のコメント
Erin Winkler
Erin Winkler 2018 年 7 月 19 日
I have tried this but I'm running into the same issue I was with user OCDER above. The index is not grabbing all of the values that make the statement:
I = num(:,20) == 1 | num(:,20) == 7
true. I have checked that the column is correct and that the size of raw is the same as num. What do I need to change to get this to work correctly?
Erin Winkler
Erin Winkler 2018 年 7 月 19 日
Never mind! I did my math incorrectly. It works.
Hail Nimrod!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by