The slicing is not complete!
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
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
abs(x - 0.3) < eps % element 4 matches
参考
カテゴリ
Help Center および File Exchange で Resizing and Reshaping Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!