Index exceeds matrix dimensions.

i wrote codes: {for s = 1: 24 sigma{s,1} = var (X{s}); y{s,1} = sigma{s+1} - a*sigma{s}*a end} where a is nxn matrix. however, i got the Index exceeds matrix dimensions error. i know for s=24; y = sigma(25)-a*sigma(24)*a and sigma(25) doesn't exist.. so how to solve it? very appreciate ur kindness..

 채택된 답변

Walter Roberson
Walter Roberson 2011년 6월 16일

0 개 추천

Your code appears to be wrong even for other cases. For example, when s = 1, you set sigma{1} first, and then constructing y, you reference sigma{2} which you have not defined yet.
It is difficult for us to tell you how to solve the problem as it is not clear what you are trying to do.

댓글 수: 3

srycandy
srycandy 2011년 6월 16일
owh.. i didn't realise that.. so i hv to put the command: { y{s,1} = sigma{s+1} - a*sigma{s}*a;} after the loop end.. then, i still get the same error. act, i'm trying to get the y values which is 3x3 matrix. is my explanation clear?
Walter Roberson
Walter Roberson 2011년 6월 16일
How do you want to define y{24,1} ? What result do you want for it?
You will need two loops (well, I might perhaps be able to write it with one, but two would be easier.)
You could also consider using cellfun. For example,
sigma = cellfun(@var, X);
would completely replace the looped calculation of sigma{s}
srycandy
srycandy 2011년 6월 19일
thank you some much.. u're right.. it's much more easier if we write it in two..

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by