How do I find if a value exists already in cell array's column, and then select the column & row to store some output data based on whether its existing or new?

28 ビュー (過去 30 日間)
I have a set of data files I am reading in from the drive. There are about 60 unique IDs, each of which can have up to six files (days 1-6, and order matters), but some are missing at random. I can read in the day number (daynum) and ID from the files. The files are named such that all the extant files for each ID are in serial before any files from the next ID.
I wrote a script to give me the means of the data I am interested in, but I'm running into problems trying to setup my output matrix such that the output fits the existing database (one row per ID, including blanks for missing data), like so: ID, Day1AvgA (D1A), Day1AvgB (D1B), Day1AvgC (D1C), D2A, D2B, D2C, .... D6C.
I have code that handles the horizontal shift:
if daynum == 1; output{ct,2} = avgrest; output{ct,3} = avgbrwo; output{ct,4} = avgbrwi; elseif daynum=2...end
for the six days, where ct is the for-loop's incremental counter.
Where I'm getting hung up is trying to solve the issue of getting all of the means for each ID into one row. I eventually went to a blunt approach using "try":
try; if id == output{ct-1,1}; Y = ct-1; end; end
... and so on up to ...
try; if id == output{ct-5,1};Y = ct-5; end; end
since that would compare the ID against that of previous six files. While inefficient, it seemed like it might work, but it created gaps between the array rows that contain data. When I tried to solve that problem with an else statement in the last try/if statement, using
else Y = find(cellfun('isempty', output),1);
to get it Y to correspond with the first empty row if it is unique, that option essentially negated the try statements.

採用された回答

Hiro Yoshino
Hiro Yoshino 2020 年 2 月 4 日
There are many useful functions for preprocessing the data:
Why don't you start using them first to get rid of rubbish in the data?
  2 件のコメント
Andrew Teer
Andrew Teer 2020 年 2 月 4 日
編集済み: Andrew Teer 2020 年 2 月 4 日
Do you know if the the "remove missing" function would remove just the rows that are completely empty? I need to preserve the columnar locations of the data.
Hiro Yoshino
Hiro Yoshino 2020 年 2 月 4 日
Yes. You should check with the documentation I attached rather than asking someone for the sake of the accuracy of information.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeWhos についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by