フィルターのクリア

Debugging matrix dimensions error

2 ビュー (過去 30 日間)
Deepayan Bhadra
Deepayan Bhadra 2019 年 11 月 26 日
回答済み: James Tursa 2019 年 11 月 26 日
I've a piece of code as follows:
data.r = zeros(Nr,N_experiments,end_sample-start_sample+1);
data.u = zeros(Nu,N_experiments,end_sample-start_sample+1);
data.y = zeros(Ny,N_experiments,end_sample-start_sample+1);
for k_exp = 1:N_experiments
for k_real = 1:N_realizations
for nr = 1:Nr
data.r(nr, k_exp,1:(end_sample-start_sample+1),k_real) = R((((k_exp-1)*N_realizations+(k_real-1))*(end_sample-start_sample+1)+1):(((k_exp-1)*N_realizations+k_real)*(end_sample-start_sample+1)),nr)';
end
for nu = 1:Nu
data.u(nu, k_exp,1:(end_sample-start_sample+1),k_real) = U((((k_exp-1)*N_realizations+(k_real-1))*(end_sample-start_sample+1)+1):(((k_exp-1)*N_realizations+k_real)*(end_sample-start_sample+1)),nu)';
end
for ny = 1:Nu
data.y(ny, k_exp,1:(end_sample-start_sample+1),k_real) = Y((((k_exp-1)*N_realizations+(k_real-1))*(end_sample-start_sample+1)+1):(((k_exp-1)*N_realizations+k_real)*(end_sample-start_sample+1)),ny)';
end
end
end
Dimensions as follows: Nr=2,Nu=2,Ny=2,N_experiments=2,N_realizations=1,start_sample=1441,end_sample=159951, R,U,Y=158511x2.
I get a 'Index exceeds matrix dimensions' error. This doesn't happen for k_exp = 1. I'm a little confused as some friends have used this same snippet and it has worked for them. What am I missing out?

採用された回答

James Tursa
James Tursa 2019 年 11 月 26 日
How to debug:
Type the following at the MATLAB prompt:
dbstop if error
Then run your code. When the error occurs, the code will pause with all variables intact. Examine the variables on the line in question to see what the actual dimensions are. Then backtrack in your code to figure out why the dimensions or indexing are not what you expected.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDebugging and Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by