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?

조회 수: 30 (최근 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 CenterFile Exchange에서 Whos에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by