フィルターのクリア

Error Using Horzcat: Dimensions of matrices being concatenated are not consistent

3 ビュー (過去 30 日間)
goyanks1989
goyanks1989 2016 年 1 月 20 日
編集済み: Star Strider 2016 年 1 月 20 日
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 件のコメント
Star Strider
Star Strider 2016 年 1 月 20 日
Your variables ‘goodPoints1’ and ‘goodPoints2’ are vectors of indices, so their order may be important.
What do you want to do with them?
goyanks1989
goyanks1989 2016 年 1 月 20 日
'goodpoints1' and 'goodpoints2' represent two separate time periods that I am trying to plot the associated variables with (I am not interested in the block of time between the 'goodpoints1' and 'goodpoints2')
My previous error was:
%
Index exceeds matrix dimensions.
Error in NonConvective (line 74)
bigDATA(ii, bigDATAstart:(bigDATAstart - 1 +length(goodPoints))) = a(goodPoints);
when I had it formatted like this:
%
goodPoints1=(utcStarts1(jj):1:utcEnds1(jj));
goodPoints2=(utcStarts2(jj):1:utcEnds2(jj));
goodPoints=[(goodPoints1), (goodPoints2)];
%
and I believe the error was in 'a(goodpoints)' as what this was generating corresponded to the actual time value, not the location in the array (ex. the first value would come up as 50000 utc but I want it to be 1)
This is why I fixed the code to
%
goodPoints1 = find((utcTime >= utcStarts1(jj)) &( utcTime <utcEnds1(jj)));
goodPoints2 = find((utcTime >= utcStarts2(jj)) &( utcTime <utcEnds2(jj)))
But now I get the horzcat error because (I think) in goodPoints = [goodPoints1, goodPoints2], the number of rows are different in each one.

サインインしてコメントする。

回答 (1 件)

Star Strider
Star Strider 2016 年 1 月 20 日
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 件のコメント
goyanks1989
goyanks1989 2016 年 1 月 20 日
I wish I had a better idea of what I was doing as well. Thank you for your help
Star Strider
Star Strider 2016 年 1 月 20 日
編集済み: Star Strider 2016 年 1 月 20 日
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by