error index exceeds matrix dimensions
조회 수: 1 (최근 30일)
이전 댓글 표시
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
댓글 수: 1
Stephen23
2017년 12월 9일
@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.
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!