이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
MATLAB Debugging Error Message
조회 수: 1 (최근 30일)
이전 댓글 표시
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
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
T
2013년 3월 4일
Suppose I have another set:
a= 0.3230
0.3570
0.3560
0.3750
0.5150
0.5150
0.3230
0.3570
0.3560
0.3750
0.5150
0.5150
0.3230
0.3570
0.3560
0.3750
0.5150
0.5150
0.3230
0.3570
0.3560
0.3750
0.5150
0.5150
0.3230
0.3570
0.3560
0.3750
0.5150
0.5150
0.3230
0.3570
0.3560
0.3750
0.5150
0.5150
test = [find(a == min(a)) < find(a == max(a))]+1;
Now it usually works for other data sets but because the sequence is as follows:
0.3230
0.3570
0.3560
0.3750
0.5150
0.5150
it doesn't decline at the end, only steadily increases up to a maximum.
What 'test' does is detect a peak but it can't without a smaller value after 0.515 .
find( a == min(a)) gives:
1
7
13
19
25
31
find(a == max(a)) gives:
5
6
11
12
17
18
23
24
29
30
35
36
The error I receive is:
Error using <
Matrix dimensions must agree.
I think this has to do with the fact that I have two values, that is 0.515 and 0.515 that are maximum and the same. How can I avoid this error?
Walter Roberson
2013년 3월 4일
That sounds like a completely different Question.
The answer to it is going to depend on what you want done in this situation. While you are at it, you should also consider possibilities such as
5 10 2 3
where the global minimum is after the global maximum.
T
2013년 3월 4일
편집: T
2013년 3월 4일
Well with the above, wherever it detects a local maximum, and local minimum, it finds those elements and if it satisfies the inequality <.
Does
test = [find(a == min(a)) < find(a == max(a))]+1;
not already satisfy
5 10 2 3?
I just want to be able to label these peaks, which I have done but came across this unique dataset and I'm not sure how to tank into account the repeated consecutive entries.
0.3230
0.3570
0.3560
0.3750
0.5150
0.5150
Walter Roberson
2013년 3월 4일
min(a) and max(a) are non-local min and max. For a=[5 10 2 3], the find(min) would report 3, find(max) would report 2, then 3<2 is false, which is numeric 0, add 1 to get 1... and then?? Clearly I could have added more numeric padding before the 10, but 1 would still have been reported (the same as if there was no peak because the values were strictly descending)
If you are looking for local peaks, look at diff(a)<0
Meanwhile, consider find(a == min(a),1) and find(a == max(a),1)
T
2013년 3월 4일
편집: T
2013년 3월 4일
Actually I still encounter the same problem with repeated values:
idx = [1;find(a >= 0.9*max(a))];
for k = 1:length(idx)-1
TestLbl(k,:) = sprintf('Test #%3d',k);
end
for j = 1:length(idx)-1
text(Times(2,j), 0.75, TestLbl(j,:), 'FontSize',12, 'HorizontalAlignment','right')
end
Gives me the following error:
Index exceeds matrix dimensions.
The above works fine for most datasets that I am dealing with except the one mentioned in the original post:
0.3230
0.3570
0.3560
0.3750
0.5150
0.5150
Walter Roberson
2013년 3월 4일
편집: Walter Roberson
2013년 3월 4일
Which line is the error occurring on? What is size(Times) ?
Why are you still assuming that all the labels will come out as the same size?
for k = 1 : length(idx)-1
text(Times(2,j), 0.75, sprintf('Test #%d', k), 'FontSize' 12, 'HorizontalAlignment', 'right');
end
T
2013년 3월 4일
The error occurs here:
text(Times(2,j), 0.75, sprintf('Test #%d', k), 'FontSize' 12,
not size(Times) but text(Times(2,j).
Times =
1.0e+004 *
0.4494 0.6111 0.7298 0.9002 1.0187 1.1038
0.4505 0.6116 0.7300 0.9006 1.0189 1.1042
0.4512 0.6120 0.7303 0.9008 1.0191 1.1048
0.4525 0.6126 0.7307 0.9011 1.0194 1.1061
0.4536 0.6132 0.7311 0.9014 1.0196 1.1071
0.4559 0.6137 0.7315 0.9017 1.0199 1.1083
0.4571 0.6143 0.7319 0.9020 1.0202 1.1093
Same size? Are you referring to sprintf?
Walter Roberson
2013년 3월 4일
Yes, as discussed above, sprintf() will produce strings of different lengths for format %d according to how many characters are needed to represent the value. You were then storing the potentially-different-length strings into TestLbl(k,:) which is a construct that would only permit strings that were all the same length. The alternative code I gave avoids this problem.
Now when the error occurs, please show the value of "j" and show the value of size(Times) (not size(Times(2,j))
T
2013년 3월 4일
편집: T
2013년 3월 4일
so for this data set:
a= 0.3230
0.3570
0.3560
0.3750
0.5150
0.5150
0.3230
0.3570
0.3560
0.3750
0.5150
0.5150
0.3230
0.3570
0.3560
0.3750
0.5150
0.5150
0.3230
0.3570
0.3560
0.3750
0.5150
0.5150
0.3230
0.3570
0.3560
0.3750
0.5150
0.5150
0.3230
0.3570
0.3560
0.3750
0.5150
0.5150
Putting the break (--->)
idx = [1;find(a >= 0.9*max(a))];
for k = 1:length(idx)-1
------------> TestLbl(k,:) = sprintf('Test #%3d',k);
end
for j = 1:length(idx)-1
text(Times(2,j), 0.75, TestLbl(j,:), 'FontSize',12, 'HorizontalAlignment','right')
end
size(Times)
ans =
7 6
The error occurs at the text(Times(2,j),.....
Walter Roberson
2013년 3월 4일
편집: Walter Roberson
2013년 3월 4일
And what is the value of "j" at that point? And what is length(idx) ? 13, right? How did you decide that Times should have 6 columns?
Walter Roberson
2013년 3월 5일
If the width of Times is not being determined by the same process that determines the peak positions, then one or the other is incorrect.
T
2013년 3월 5일
편집: T
2013년 3월 5일
It works for two other data sets and I suspect that the reason why it doesn't work for this one is because there are two maximum and two minimum for which test_idx gets those elements for thereby increasing the the length of that vector when it fact it should be half of what it is.
So, how does one, when using test_idx = [1;find(a >= 0.9*max(a))] take into account for repeated maximum?
When does not have to check for global max and min and I have set, I removed the inequality because it's not necessary. I don't even know why I bothered. All I needed was the maximum.
T
2013년 3월 5일
find(diff(wt)==0) works but only for that particular case and fails for the rest. The or operator will not work with test_idx because the inputs do not have the same size. I could try removing the repeated index then take the maximum.
T
2013년 3월 5일
편집: T
2013년 3월 5일
I got something that works:
if find(diff(a)==0)
what = (diff(a)==0)
label = find(what == 1)
else
label = [find(a >= 0.9*max(a))]
end
test_idx = [1;label]
however,
for k1 = 1:length(test_idx)-1
TestLbl(k1,:) = sprintf('Test #%3d',k1);
end
gives me odd results for the data set mentioned for the original post.
Even though I don't get an error, the output for the data in the original post doesn't display the word Test #.
It probably has to do with the order of the if statements.
T
2013년 3월 5일
Do I need to be concerned with duplicates not at the max?
find(a >= 0.9*max(a)) only looked for max values, which is all I need and what was being repeated was the maximum values.
Walter Roberson
2013년 3월 7일
find(diff(a)==0) finds duplicates even if they are not at the maximum. And if it does then you do not proceed to testing for 0.9 times the maximum.
T
2013년 3월 7일
편집: T
2013년 3월 7일
You're right.
I was playing with histc(a)
So if
a = [1 2 3 4 5 5 6 8 9 1 2 6 9 9 12];
I = histc(a,a(1):a(end));
find(I>1)
ans =
1 2 5 6 9
However when I try it with the data above, vector a is not expressed as
a = [ ... ]
How do I convert our 'a' into this format [ ] as opposed to just
a = 2 4 5 6 7 8 and so on?
Or I could try max(a) == mode (a)
T
2013년 3월 7일
No it just doesn't show the label for the dataset in the original post, as with every other attempt I've made.
T
2013년 3월 8일
Actually I was wrong,
when ever I put the break on
if (max(a) == mode(a))==1
A new window pops up mode.m with the green arrow pointing to
if nargin<2
Do you know what's wrong?
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Preprocessing에 대해 자세히 알아보기
태그
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)