Vec = [0 -0 0 -0 0 0 0 0 1 0 0 0 -0 3 4 0 -0 0 0]
First step find non-zero value.
[Vecindex] = find(abs(Vec)>0)
Vecindex= 9 14 15
Q1. How to plus between indices?
  • 1+0 (indices is 9 and 10)
  • 3+4 (indices is 14 and 15)

댓글 수: 4

Roger Stafford
Roger Stafford 2016년 5월 16일
Please expand on your phrase “How to plus between indices”. I don’t know what you mean by that. Show a vector with a larger number of non-zero values and the result you expect, in order to demonstrate what you mean.
DongShin Yang
DongShin Yang 2016년 5월 16일
I want to revise vector value and index.
A = [ 0 0 0 0 2 0 0 0 1 4 0 0 ]
Revised A is that
A = [ 0 0 0 0 2 0 0 0 5 0 0 0 ]
The indices and value were revised by
2 index(5) + 0(index(6)next to value )
1(10) + 4(11) = 5 and index (10)
Note that
find(Vec) %no need for abs(Vec)>0
is sufficient to find the indices of non-zero values
Also note that matlab does not have a concept of negative zero.
Finally, what should happen with:
Vec = [0 1 0 0 3 4 6 0 0]
Are the 3 4 6 all summed together or just 3 and 4?
Roger Stafford
Roger Stafford 2016년 5월 16일
@Guillaume: Actually, because most computers that run Matlab adhere to the 754 IEEE Standard for Binary Floating-Point Arithmetic, these do have the concept of a negative zero. You can tell the difference between the two kinds of zero by dividing 1 by them. A plus zero will give inf and a minus zero will produce -inf. Also fprintf will exhibit a minus sign on minus zero. Using format hex also reveals the difference.

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2016년 5월 16일

0 개 추천

strfind(Vec, [1 0])
strfind(Vec, [3 4])

댓글 수: 1

DongShin Yang
DongShin Yang 2016년 5월 16일
Thank your help. But because of rack of my explain. Your answer was different. Sorry. I want to find non-zero value and indice and Plus first one and next one, then, Revise index of result of plus.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

질문:

2016년 5월 16일

댓글:

2016년 5월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by