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!