フィルターのクリア

Selecting a single value with max function - Subscripted assignment dimension mismatch.

4 ビュー (過去 30 日間)
Hello, I am having the error message ??? Subscripted assignment dimension mismatch, an I believe that it is caused because when I use the max function, it finds two maximum values and tries to return both of them. Is there a way to return one value? The part of code that I get the error is shown below: Line No 5.
A = rpm((i-19):(i-10),1);
rpmGS(c,1) = max(A);
num = max(A);
row=find(A==num)+(j-2)*10+3;
%ratioGS(c,1) = ratio(row,1);% This is the error line.
velocityGS(c,1) = a(row-3,6);
c=c+1;

採用された回答

Walter Roberson
Walter Roberson 2012 年 6 月 25 日
The max() is only returning one value. The find(A==num) is returning 2. If you only want one returned you can use find(A==num, 1). Or, as indicated by "grapevine" you can use the two-output version of max() to return the location instead of doing the find()
[num, indexMax] = max(A);
row = indexMax + (j-2)*10+3;

その他の回答 (1 件)

grapevine
grapevine 2012 年 6 月 25 日
I'm not sure about that Check this code
A=[2, 2, 3, 3]
[num, indexMax] = max(A)
size(num)
length(num)
I think the error is elsewhere, but you didn't give us enough information to help you

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by