for loop involving matrix with 3 indices
Mostra commenti meno recenti
Hi,
I am trying to obtain a matrix with 3 indices (represented by m, j, n respectively) via the use of a for loop. The general idea looks something like this:
I first set up the matrix to be x=zeros(M+1,J+1,N+1), where M J N are predefined constants;
I then created a triple for loop that resembles -
for n = 2:1:N+1
for m = 2:1:M+1
for j = 2:1: J+1
x(m,j,n) = ...
end
end
end
When I tried to run the code, however, I got an error message at "x(m,j,n) = ..." that says "Index in position 3 exceeds array bounds. Index must not exceed 1." Can someone enlighten me on why this error message popped out? I was certain that x was set up properly at "x=zeros(M+1,J+1,N+1)". Thanks!
5 Commenti
x(m,j,n) = ...
% ^^^^ The problem is here,
% ^^^^^ not here.
You are trying to access an element of an array that does not exist. But as you did not show or explain anything about the RHS, we cannot easily help you debug invisible code.
Mingze Yin
il 9 Gen 2022
Mingze Yin
il 9 Gen 2022
Mingze Yin
il 9 Gen 2022
x=zeros(M+1,J+1,N+1)
Vp1(m+1,j,n)
% ^^ problem is in this matrix
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!