MATLAB Answers

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?

2 views (last 30 days)
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.

  0 Comments

Sign in to comment.

Accepted Answer

Hiro Yoshino
Hiro Yoshino on 4 Feb 2020
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 Comments

Andrew Teer
Andrew Teer on 4 Feb 2020
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 on 4 Feb 2020
Yes. You should check with the documentation I attached rather than asking someone for the sake of the accuracy of information.

Sign in to comment.

More Answers (0)

Sign in to answer this question.

Tags

Products


Translated by