Clear Filters
Clear Filters

Info

This question is closed. Reopen it to edit or answer.

Index exceeds matrix dimensions

2 views (last 30 days)
sihem bk
sihem bk on 5 Nov 2018
Closed: MATLAB Answer Bot on 20 Aug 2021
Hello,i'm trying to plot the synchronization error under the hybrid control, iget this error :
Index exceeds matrix dimensions.
Error in Untitled21 (line 16)
e(:,k+1)= (A*((Y(k ,:))-(x(:,k))))+(fy-fx);
and this my code :
clear all
clc
a=1.07;
b=0.3;
n= 50;
K(1)=0;
%Z(1)=0;
x(:,1)=[(-1.2) ; 0 ; 0.3 ];
y(1,:)=[(-1.54); 0 ; 0.46];
Y=transpose(y)
for k=1:n
%for Z=1:n
fx=[1-a*((x(1))^2)*(k) ; 0 ;0 ];
fy=[1-a*((Y(1))^2)*(k) ; 0 ; 0 ];
A=[0.12 -0.18 0;0 0.15 -0.18;0 0 0.18];
e(:,k+1)= (A*((Y(k ,:))-(x(:,k))))+(fy-fx);
K(k+1)=k;
%end
end
plot(K,e(1,:),'red')
hold on
plot(K,e(2,:),'green')
hold on
plot(K,e(3,:),'blue')

Answers (1)

Tally Miller
Tally Miller on 5 Nov 2018
I don't know what you are trying to do here, but you are getting the error message because you are trying to access x(:,k) when x is a matrix with the dimensions [3,1]. It happens once i is greater than 1.
The debugging tool might help you with this.

This question is closed.

Products

Community Treasure Hunt

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

Start Hunting!