matrix and steps in column
Show older comments
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?
Answers (1)
Image Analyst
on 6 Dec 2020
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);
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!