Compare two vectors and assigning values then adding to a empty vector

조회 수: 11 (최근 30일)
Saurabh Sawant
Saurabh Sawant 2018년 3월 24일
편집: David Fletcher 2018년 3월 24일
So I am trying to compare two vectors of vector lol2>lol1 the value should be 0 and if vector lol2<lol1 value should be 1, and I want to iterate these values and add them to an empty vector. Here is what I have
lol=[];
% for i=1:1:999
% if hue2(i)>hue1(i)
% z=0;
% if hue2(i)<hue1(i)
% z=1;
% lol=[lol k]
% end
% end
% end
so the answer should be like lol=[0,1,1,1,1,...]

답변 (1개)

David Fletcher
David Fletcher 2018년 3월 24일
편집: David Fletcher 2018년 3월 24일
result=hue2<hue1
Will return a logical vector with a 1 wherever hue2<hue1 and a 0 otherwise. If you want this as a double rather than a logical vector, you can cast it to double (or whatever you require)
double(result)

카테고리

Help CenterFile Exchange에서 Simulink에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by