How to: For loop and matrix indexing in matlab?
조회 수: 4 (최근 30일)
이전 댓글 표시
I = 5; % e.g number of nodes
for i =1:I
initial_matrix = [0]; % an initial matrix will be generated for each node
end
Now, i want to skip the initial_matrix of node 1 and consider the initial_matrix of all other nodes (nodes 2,3,4 and 5) and subtract each of them from 1 and take their product:
(1 - initial_matrix of node 2) * (1 - initial_matrix of node 3) * (1 - initial_matrix of node 3) * (1 - initial_matrix of node 4) * (1 - initial_matrix of node 5).
- So for each node i, I will consider all other nodes but not the node i itself
Can any one tell me or give me hints on how this can be achieved? Thanks!
댓글 수: 1
Jan
2013년 9월 11일
편집: Jan
2013년 9월 11일
The question is unclear. The posted code does not create a vector, but creates the same scalar variable in each iteration. The term "node" is not clear - does "initial_matrix of node 2" mean initial_matrix(2) ?
Creating a vector of zeros is surely a task for the zeros command. Then subtracting the values from 1 and multiplying the results creates 1. So the aim of your code is not clear. I assume you simplified too much.
답변 (1개)
Simon
2013년 9월 11일
Hi!
Your code only gives you a scalar "initial_matrix" with value 0.
Take a look at http://www.mathworks.com/help/matlab/math/matrix-indexing.html to read about indexing.
댓글 수: 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!