Sateflow: Indexing an array of size 1
2 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I need to index an array that can be of size 1 to x. Indexing in gerneral is no issue, as long as the size of the array is >1 (e.g. using A[x]). But as soon as the array size is 1 I get the following error for a transition check:
[i == 0 && A[i] >= B[i]]
Array dimension mismatch for data A.
Size of a is defined empty.
Anyone an idea for a generic approach?
Thanks!
0 件のコメント
回答 (1 件)
Prateekshya
2024 年 8 月 21 日
Hello Maciej,
The error you are getting is due to invalid indexing. MATLAB follows 1-based indexing i.e. the first index is 1. Here is an example to deal with arrays in MATLAB:
% Example arrays A and B
A = [5]; % Can be of size 1 to x
B = [3]; % Can be of size 1 to x
% Determine the size of the array
n = numel(A); % Get the number of elements in A
% Initialize a variable to store the result
result = false;
% Loop through the array with safe indexing
for i = 1:n
% Check the condition with safe indexing
if (i == 1) && (A(i) >= B(i))
result = true;
break; % Exit the loop if condition is met
end
end
% Display the result
if result
disp('Condition met: A[i] >= B[i] for i == 1');
else
disp('Condition not met.');
end
I hope this resolves your query.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Multidimensional Arrays についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!