matrix and steps in column

1 次查看(过去 30 天)
Jiung Shin
Jiung Shin 2020-12-6
My matrix A is nx3 matrix and X is entry of A at (t,2) and t is assignmed in previous line.
I expressed it as X(t)=A(t,2). But when I ask for X(t+1), it returns this error:
Index exceeds the number of array elements (3).
Error in sym/subsref (line 907)
R_tilde =
builtin('subsref',L_tilde,Idx);
If I want to calculate X(t+1)-(X), how should I change my code?

回答(1 个)

Image Analyst
Image Analyst 2020-12-6
Did you also assign X in advance? Why do you think there should be a t+1 element of X if you never assigned one?
n = 9;
A = rand(n, 3);
t = 4; % Whatever.
X(t) = A(t, 2); % Works fine
% The following won't work because X has only 4 elements, not 5
difference = X(t+1) - X(t); % There is no (t+1) element yet!
Not sure what you want to do Maybe you want this:
X = diff(A(:, 2);

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by