how can i check if a cell is equal to summation of other cells?

1 回表示 (過去 30 日間)
MAHMOUD ALZIOUD
MAHMOUD ALZIOUD 2018 年 1 月 25 日
コメント済み: MAHMOUD ALZIOUD 2018 年 1 月 25 日
Dear All, I have a matrix of 5 columns and many rows, the first column A is the total weight of a car, the rest of the four columns are the individual weight each wheel carries, as a quality check, I need to check if every cell in the 1st column is really equal to the summation of the last four columns B to E, and if not delete this row because it will corrupted data, how can I do that in matlab? is there any (is equal) thing?

採用された回答

the cyclist
the cyclist 2018 年 1 月 25 日
編集済み: the cyclist 2018 年 1 月 25 日
One should not check floating-point numbers for exact equality, due to possible error in exact representation. Here is a simple method that will check for equality within a tolerance you define.
% The data
M = [3 1 2;
4 1 3;
6 1 4];
% Define a tolerance for equality
tol = 1.e-6;
% Test for equality within tolerance
abs(M(:,1)-sum(M(:,2:end),2)) < tol;
  2 件のコメント
MAHMOUD ALZIOUD
MAHMOUD ALZIOUD 2018 年 1 月 25 日
this is a brilliant idea, i will try it now
MAHMOUD ALZIOUD
MAHMOUD ALZIOUD 2018 年 1 月 25 日
i have a question please, what do you mean by 2 in the last line ? the last 2 in the line what is it for?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by