i have matrix posi_sign with size 384x2 double. Then when i recall matrix in exact position with posi_sign(8,2):posi_sign(end,2) the result
ans = 1×0 empty double row vector
and then i try different position --> posi_sign(8,2):posi_sign(10,2) and it has answers like this ans =
420 421 422 423 424 425 426 427 428
but when i try until posi_sign(14,2) the result is
ans = 1×0 empty double row vector
anyone can help why this is happened?

 Accepted Answer

Stephen23
Stephen23 on 5 Jul 2018
Edited: Stephen23 on 5 Jul 2018
"anyone can help why this is happened?"
Because that is not how to use indexing if you want a subset of that matrix. Try these instead:
posi_sign(8:end,2)
posi_sign(8:10,2)
What you are doing is to use indexing to extract elements from the matrix, and using those element values as the end-points for the colon operator. So the output depends entirely on whatever values those elements happen to have. Here is a simple example of what you are doing:
>> V = [99,0,123,69];
>> V(1):V(3)
ans =
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
Element V(1) has value 99, and element V(3) has value 123, and those are the inputs you use to the colon operator. Whereas it appears you actually want to be doing this:
>> V(1:3)
ans =
99 0 123
Basic MATLAB concepts, like how to use indexing, are explained in the introductory tutorials, which are highly recommended for all beginners:

More Answers (0)

Community Treasure Hunt

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

Start Hunting!