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 CenterFile Exchange에서 Data Preprocessing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by