1

I am just learning MATLAB for the first time.

I am reading some code trying to understand it. I believe I have two arrays below called pdw_raw & pdw_factors which contains a list of dates. The line that is causing me most confusion is the last line in the code below. The only way I can seem to make sense of this line is that every element in pdw_raw is being check against the max date of pdw_factors - is this correct?

Find the MATLAB syntax hard to understand at the moment.

%first retrieve the relevant dates;
sql_statement   = ['select distinct pricedatew from D_RAWRETS order by pricedatew'];
cursor          = exec(QES_DB, sql_statement);
cursor          = fetch(cursor);
pdw_raw         = datenum(cursor.data);
pdw_raw         = pdw_raw(1:end-1, 1);

sql_statement   = ['select distinct pricedatew from D_FACTORS order by pricedatew'];
cursor          = exec(QES_DB, sql_statement);
cursor          = fetch(cursor);
pdw_factors     = datenum(cursor.data);

missing_dates   = pdw_raw(pdw_raw > max(pdw_factors));

1 Answer 1

2

That is correct.

pdw_raw > max(pdw_factors) creates an array of logicals that is true for elements of pdw_raw that are bigger than the largest pdw_factors elements, and false otherwise.

pdw_raw(pdw_raw > max(pdw_factors)); uses logical indexing to extract only the elements for which pdw_raw > max(pdw_factors) is true.

Sign up to request clarification or add additional context in comments.

3 Comments

+1, @mHelpMe: Note that max returns a vector if the input argument is a 2D-matrix. I.e. it returns the maximum value of each column, not the overall maximum as a single number.
@RobertP. true, but in this case pwd_factors comes from a sql query that only selects a single column so it is safe to assume that it is a vector.
I know =) It was just a small reminder to OP, as it is not intuitive and could easily cause problems in other situations.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.