Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
index of zero prolem in matlab
조회 수: 4 (최근 30일)
이전 댓글 표시
hi, is there solution for index of zero problem. I'm facing this problem in this code I'm working to design code of local sequence alignment(smith_watrman algorithm)
it is very necessary to fill the first column (zero column) and the first row(zero row) with zero value as initial matrix, then fill the other cells of array with values gradually.
how can run this code? is there another way?
for j=1:length(x)
mat(0,j).scor=0;end;
for i=1:length(y)
mat(i,0).scor=0;end;
%%%%fill matrix
for i=1:length(y)
for j=1:length(x)
%%%%%%calculate match score
letter1=x(j-1:j-1);letter2=y(i-1:i-1);
etc....
end;end;end;
thanks
댓글 수: 0
답변 (1개)
Andrew Newell
2011년 12월 29일
You seem to have a structure array. You could initialize it using
mat = repmat(struct('scor',0),length(y),length(x));
댓글 수: 1
Walter Roberson
2011년 12월 29일
Yes, that should be effective enough in most cases.
This will, however, use the "same" scalar 0 to initialize all of the locations, with new memory allocated the first time it becomes necessary to write a value at a location. In some cases it can be important to allocate all of the memory first. The vectorized ways of doing that tend to temporarily require about double the memory, though, so a loop can end up being what you should use.
It will not be possible to assign to index 0 -- not unless you create your own OOP class with a subsref and subsassgn method that understands an index of 0. If there was a good reason why that was necessary (instead of just changing the index calculations) then some of the contributions in the File Exchange might help.
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!