Filter löschen
Filter löschen

Sateflow: Indexing an array of size 1

3 Ansichten (letzte 30 Tage)
Maciej
Maciej am 16 Dez. 2013
Beantwortet: Prateekshya am 21 Aug. 2024
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!

Antworten (1)

Prateekshya
Prateekshya am 21 Aug. 2024
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.

Kategorien

Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by