matlab horzcat CAT arguments dimensions are not consistent.
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Saúl
am 29 Aug. 2014
Kommentiert: Geoff Hayes
am 29 Aug. 2014
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 Kommentare
Akzeptierte Antwort
Star Strider
am 29 Aug. 2014
Bearbeitet: Star Strider
am 29 Aug. 2014
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.
2 Kommentare
Weitere Antworten (1)
Geoff Hayes
am 29 Aug. 2014
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 Kommentare
Geoff Hayes
am 29 Aug. 2014
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.
Siehe auch
Kategorien
Mehr zu Sparse Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!