MATLAB Debugging Error Message

1 回表示 (過去 30 日間)
T
T 2013 年 3 月 4 日
test_idx =
1
1
7
13
19
25
31
37
43
49
55
for k1 = 1:length(test_idx)-1
TestLbl(k1,:) = sprintf('Test #%d',k1);
end
Subscripted assignment dimension mismatch.
Error in test>LabelPeak_Callback (line 563)
TestLbl(k1,:) = sprintf('Test #%d',k1);
What does this mean?

採用された回答

Walter Roberson
Walter Roberson 2013 年 3 月 4 日
When you use sprintf() with a %d format, the number is converted into the minimum number of characters needed for it. For 1, 1, and 7, that is one character, so for those three the resulting strings are all the same size. But then you reach 13 and that takes two characters to output, so the resulting string is longer than the ones before. You are using TestLbl(k1,:) as the destination so you are trying to write a row which is longer than the existing rows. You cannot have rows of different lengths in a character array.
You need to assign to TestLbl{k} (a cell array entry) or else you need to ensure that the strings are all the same size such as using %3d instead of %d. %3d means to use at least 3 characters, so for example space-space-7 for 7.
  31 件のコメント
Walter Roberson
Walter Roberson 2013 年 3 月 9 日
Recode as
Tmode = mode(a);
Tmax = max(a);
if Tmode == Tmax
That way you can examine the parts of the calculation.
mode() really seems unlikely to me to be useful in this situation. Did you notice that if there are multiple values with equal maximum counts, that it returns the smallest of them? So
[1 2 3 3 4 5 6 7 7]
would return 3
T
T 2013 年 3 月 11 日
that works thanks.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Preprocessing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by