MATLAB Debugging Error Message

1 vue (au cours des 30 derniers jours)
T
T le 4 Mar 2013
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?

Réponse acceptée

Walter Roberson
Walter Roberson le 4 Mar 2013
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 commentaires
Walter Roberson
Walter Roberson le 9 Mar 2013
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 le 11 Mar 2013
that works thanks.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Data Preprocessing dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by