Error Using Horzcat: Dimensions of matrices being concatenated are not consistent
Mostra commenti meno recenti
I am receiving the following error message:
Error using horzcat
Dimensions of matrices being concatenated are not consistent.
Error in test (line 55)
goodPoints = [goodPoints1, goodPoints2];
where
%
goodPoints1 = find((utcTime >= utcStarts1(jj)) &( utcTime <utcEnds1(jj)));
goodPoints2 = find((utcTime >= utcStarts2(jj)) &( utcTime <utcEnds2(jj)));
goodpoints1 is a 9532x1 double and goodpoints2 is a 8270x1 double
From my understanding this error shows because the two do not have the same number of rows. What alternatives can I use to fix this error? (in the most layman's terms possible!) Thank you for any help!
2 Commenti
Star Strider
il 20 Gen 2016
Your variables ‘goodPoints1’ and ‘goodPoints2’ are vectors of indices, so their order may be important.
What do you want to do with them?
goyanks1989
il 20 Gen 2016
Risposte (1)
Star Strider
il 20 Gen 2016
Put them in a cell array instead (note the curly brackets ‘{}’):
goodPoints = {goodPoints1, goodPoints2};
Cell arrays are a bit more difficult to work with (you have to retrieve the elements of the array to calculate with it, for instance), but are quite useful in storing data such as you want to.
4 Commenti
goyanks1989
il 20 Gen 2016
Star Strider
il 20 Gen 2016
It means I have no idea what you’re doing!
The cell array I suggested has two different and unequal columns of index values. You have to refer to it something like this:
goodPoints = {randi(9, 10, 1) randi(9, 15, 1)};
a = randi([50 99], 9, 1);
output = a(goodPoints{1});
This is entirely synthetic code and is not what you are doing, but it illustrates the correct way to use a cell array of indices.
goyanks1989
il 20 Gen 2016
Star Strider
il 20 Gen 2016
Modificato: Star Strider
il 20 Gen 2016
You need to reference either column of ‘goodPoints’ here. For example:
bigDATA(ii, bigDATAstart:(bigDATAstart - 1 +length(goodPoints{1}))) = a(goodPoints{1});
although I have no idea if that is what you want to do.
My pleasure.
Categorie
Scopri di più su Creating and Concatenating Matrices in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!