フィルターのクリア

Expected a scalar value. This expression has size [:? x 1].

38 ビュー (過去 30 日間)
Praveen Kumar
Praveen Kumar 2023 年 2 月 1 日
コメント済み: Praveen Kumar 2023 年 2 月 1 日
% Sample Code
max_index = find(sample.data1 == values,1,'first');
% max_index is always above 100 based on the nature of the data
X = sample.data1(max_index - 100: max_index + 100);
Y = sample.data2(max_index - 100: max_index + 100);
I was trying to generate code based on MATLAB coder, however I am stuck with the error: 'Expected a scalar value. This expression has size [:? x 1].'
I understand that max_index could be empty or (max_index - 100) could be empty, hence this error. How to properly declare those variables to avoid this error?
Max_index is scalar value and cannot be below 100 based on the nature of used data (also used If loops to avoid such condition).

採用された回答

KSSV
KSSV 2023 年 2 月 1 日
Try this:
% Sample Code
tol = 10^-3 ; % can be changed
idx = find(abs(sample.data1-values)<tol) ;
max_index = idx(1) ;
  4 件のコメント
Praveen Kumar
Praveen Kumar 2023 年 2 月 1 日
編集済み: Praveen Kumar 2023 年 2 月 1 日
Sorry, the code works!
Previously I had pre-intialized max_index to variable size using: coder.varsize('max_index').
Removed the same and the coder generates without any error.
Praveen Kumar
Praveen Kumar 2023 年 2 月 1 日
Thanks again. Just to clarify your question.
  1. 'Values' is a single number. (I should have declared as 'Value' here (or mentioned), to avoid confusion )
  2. sample.data1 is a (nx1) vector, n>1000.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by