# The slicing is not complete!

조회 수: 2 (최근 30일)
댓글: Voss 2021년 12월 17일
Hi all,
I have the following 2D matrix and I want to slice it by taking just the elements on the first column that equal to one. The thing is tht the slicing is turns out t be 50X2 rather than 57x2.
a =[1.0000 0.0399;
1.0000 0.6043;
1.0000 0.4364;
1.0000 0.8750;
1.0000 0.8750;
1.0000 0.8750;
1.0000 0.8750;
1.0000 0.7557;
1.0000 0.8363;
1.0000 0.8123;
1.0000 0.5656;
1.0000 0.3738;
1.0000 0.0285;
1.0000 0.4316;
1.0000 0.3117;
1.0000 0.6250;
1.0000 0.6250;
1.0000 0.6250;
1.0000 0.6250;
1.0000 0.6250;
1.0000 0.9756;
1.0000 0.2671;
1.0000 0.5090;
1.0000 0.4370;
1.0000 0.3156;
1.0000 0.1238;
1.0000 0.7256;
1.0000 0.0171;
1.0000 0.2590;
1.0000 0.8757;
1.0000 0.1870;
1.0000 0.3750;
1.0000 0.3750;
1.0000 0.3750;
1.0000 0.3750;
1.0000 0.3750;
1.0000 0.3750;
1.0000 0.3750;
1.0000 0.9593;
1.0000 0.1816;
1.0000 0.0617;
1.0000 0.0656;
1.0000 0.2419;
1.0000 0.0057;
1.0000 0.0863;
1.0000 0.2919;
1.0000 0.0623;
1.0000 0.1250;
1.0000 0.1250;
1.0000 0.1250;
1.0000 0.1250;
1.0000 0.1250;
1.0000 0.1250;
1.0000 0.1250;
1.0000 0.1250;
1.0000 0.1250;
1.0000 0.9431]; %this is 57x2 matrix
E = a(a(:,1)==1, :) %this should be the same but it turns out to be 50x2!
Any help of why the slicing is throwing away 7 elements would be apprecited.
Thanks.
##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
Voss 2021년 12월 17일
Can you show the value of E which is 50-by-2? I get E is 57-by-2 as expected when I run the code.

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

### 답변 (1개)

Steven Lord 2021년 12월 16일
Most likely some of the numbers that are displayed as 1 are stored as a value that is very close to but not down-to-the-last-bit equal to 1. Some of the elements of the following vector will be 0 and some will be very small but not zero.
% Using block comments so the rest of the lines in this answer can be
% executed
%{
difference = a(:, 1) - 1
%}
Compare using a tolerance.
x = 0:0.1:1;
x == 0.3 % none match
ans = 1×11 logical array
0 0 0 0 0 0 0 0 0 0 0
abs(x - 0.3) < eps % element 4 matches
ans = 1×11 logical array
0 0 0 1 0 0 0 0 0 0 0
##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
편집: Lama Hamadeh 2021년 12월 16일
Thanks fro the reply. Why does this difference occur if I define the entries to be equal to1 from the beginning?

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

### 카테고리

Help CenterFile Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by