matlab horzcat CAT arguments dimensions are not consistent.
조회 수: 1 (최근 30일)
이전 댓글 표시
im using a matrix DATA with dimensions<245x2 double>
then
SECOND = DATA(:,2) >= 8 & DATA(:,2) <= 65 FIRST = DATA(:,1) & SECOND
how can i make them the same dimension so i can merge them in
TDOT = [DATA(FIRST,1) DATA(SECOND,2)]
댓글 수: 0
채택된 답변
Star Strider
2014년 8월 29일
편집: Star Strider
2014년 8월 29일
One option is that if they are not integer arrays, you could use the interp1 function to lengthen the shorter vector using the 'extrap' option. It depends what your data are, and what you are comfortable with. Essentially, interpolation-extrapolation amounts to ‘stretching’ the shorter vector a bit, keeping all the essential information.
Another option is that SECOND for some reason has duplicate values (that it is not supposed to) and that is causing the disparity. (Guessing here.) You could use the unique function to find the duplicated value in the longer vector and eliminate it.
추가 답변 (1개)
Geoff Hayes
2014년 8월 29일
Saúl - if you want to merge the two matrices as shown above (horizontally), the two matrices must have the same number of rows. So either remove one row from the second matrix (since it has 73 rows) or just add a row of zeros to the first matrix
TDOT = [ [DATA(FIRST,1);0] DATA(SECOND,2) ]
Try the above and see what happens!
댓글 수: 2
Geoff Hayes
2014년 8월 29일
My mistake, I hand't read the question closely enough. I'm not sure why the above code would set FIRST to one element less than SECOND. I suppose that you could figure out which row is being removed from FIRST by comparing it with SECOND. They both should have ones and zeros in the same place, except for one index where FIRST would have a zero and SECOND a one.
But do you really need both a FIRST and SECOND, since FIRST is supposed to take the only the values that match those from SECOND.
Your code could simplify to
TDOT = DATA(SECOND,:);
which would mean grab data from both columns where SECOND indicates which rows of the second column meet the specified criteria.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!