Why does an array have a different column dimension than the array used to define that array?
1 view (last 30 days)
I enclose a m file and a small data file. A is a column array with dimension 3233 by 1. B is a column array defined using A and its dimension should stay the same. It does not. It has dimension 3232 by 1. In particular, the very last element gets lost in B. What is going on?
Dyuman Joshi on 23 Jan 2023
You have defined B directly from a logical condition. When you do so, MATLAB checks for logical true values and defines accordingly; so the resulting variable is updated till the last logical true value.
Which is the 3232nd value here -
%size of y is not same as size of x
To get the desired result, you should pre-allocate B with the same size as A and then apply the condition.
Also, you should consider what values those B elements take where elements of A are not equalto 2.