scilab submatrix incorrectly defined -
i stuck @ creating matrix of matrix (vector in case)
what have far
index = zeros(size(a)) // matrix isn't important question indexindex = 1; rows=1:length(r) columns=1:length(k) if(a(rows,columns)==x) v=[rows columns]; // create vector holding row + column index(indexindex) = v(1,2) // want store these vectors indexindex = indexindex + 1 end end end i have tried various ways of getting information out of v (such v(1:2)) nothing seems work correctly.
in other words, i'm trying array of points.
thanks in advance
i not understand question exactly. size of a? x, k , r? under assumptions,
using list
you use list
// create matrix a = zeros(8,8) //initialize list index = list(); // dimensions of rows = size(a,1); cols = size(a,2); x = 0; row=1:rows col=1:cols if(a(row,col)==x) // create vector holding row , col v=[row col]; // append list using $ (last index) + 1 index($+1) = v end end end single indexed matrices
another approach make use of fact multi-dimensional matrix can indexed single value.
for instance create random matrix named a:
-->a = rand(3,3) = 0.6212882 0.5211472 0.0881335 0.3454984 0.2870401 0.4498763 0.7064868 0.6502795 0.7227253 access first value:
-->a(1) ans = 0.6212882 -->a(1,1) ans = 0.6212882 access second value:
-->a(2) ans = 0.3454984 -->a(2,1) ans = 0.3454984 so proves how single indexing works. apply problem , knocking out for-loop.
// create matrix a = zeros(8,8) //initialize array of indices index = []; // dimensions of rows = size(a,1); cols = size(a,2); x = 0; i=1:length(a) if(a(i)==x) // append list using $ (last index) + 1 index($+1) = i; end end without for-loop
if need values adhere condition this
values = a(a==x); be carefull when comparing doubles, these not (un)equal when expect.
Comments
Post a Comment