subtracting two vectors to get one value

조회 수: 11 (최근 30일)
Lev Mihailov
Lev Mihailov 2019년 9월 2일
편집: John D'Errico 2019년 9월 2일
Hello! I have two column vectors and I need to subtract them to get one value, is this possible?
  댓글 수: 2
Adam
Adam 2019년 9월 2일
Depends what you want the one value to represent?! It's a meaningless question otherwise. If the two vectors are the same length then a normal subtraction would give you a 3rd vector of that same length.
John D'Errico
John D'Errico 2019년 9월 2일
편집: John D'Errico 2019년 9월 2일
Until you define what the meaning of "a single number" is, in terms of mathematics, you cannot do anything. What would that number represent?
Two vectors. If the vectors are not the same length, then there is absolutely no meaning you can attribute to this, at least you have not done so.
Are the vectors of the same length? If they are, then you can subtract each element, IF that subtraction has any meaning. But then you have another vector of the same length. At best, you can compute some norm, as a measure of the aggregate size of the elements of that difference vector. You have not indicated this is your goal though. If that is what you wanted to do, then read the help for the function norm. You need to decide which vector norm is appropriate for your problem then.

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

답변 (1개)

madhan ravi
madhan ravi 2019년 9월 2일
편집: madhan ravi 2019년 9월 2일
Why not
vector1 - vector2 %?
If they are of different sizes:
bsxfun(@minus,vector1,vector2.') % < 2016b
% else it's simply
vector1 - vector2.'

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by