現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
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!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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 (한국어)