Clear Filters
Clear Filters

error index exceeds matrix dimensions

1 view (last 30 days)
Tejas Shetty
Tejas Shetty on 9 Dec 2017
Commented: Stephen23 on 9 Dec 2017
getting error index exceeds matrix dimensions at line h = H{m}; %index exceeds matrix dimensions inside the for loop
1.% function [rho] = blah(start,rho0)
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
load definitions.mat
load parameters.mat
[a,adag,II,A,Ad] = Nho_stuff(Nho,gam);
whos a adag II A Ad
whos start
H = Hamiltonian(start);
whos H
nt = Nt+1;
rho=cell(nt,1);
rho{1}=rho0;
m=1;
dt=tunit;
% tind=1:1:Nt;
% time=tind*tunit;
% whos H{1}
%h=zeros(length(rho0));
for i = 1: nt
if(abs(mod(i,C))<eps) %mod(i,C)=0
m=m+1;
end
h = H{m}; %index exceeds matrix dimensions
% h=H(m); %defines it as a cell rather than a matrix
% h=cell2mat(H(m)); %index exceeds matrix dimensions
ro=rho{i};
ihdt = -1i*h*dt;
ih2dt2 = 0.5*ihdt*ihdt;
droh = ihdt*ro - ro*ihdt- 2*(ihdt*ro*ihdt) + ro*ih2dt2 + ih2dt2*ro; % 0;%
dro = droh + (A*ro*Ad-(1/2)*Ad*A*ro-(1/2)*ro*Ad*A)*dt;
rho{i+1}=rho{i}+dro;
rho{i+1}=rho{i+1}/real(trace(rho{i+1}));
end
end
Remaining files could be found here total code
  1 Comment
Stephen23
Stephen23 on 9 Dec 2017
@Tejas Shetty: it is time for you to do some debugging. Start by looking at the size of H, and thinking about why you expect index m to be <= the number of elements of H.

Sign in to comment.

Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!