Clear Filters
Clear Filters

Set some values to zero regarding to anothers

2 views (last 30 days)
Hi, i want to set all values different from wx vector to zero
index=find(labels==0);
wx=full(T(index,1));% vector containing values to not be setted to zero
elements=full(T(:,1));
indexmr=find(~ismember(elements,wx));% find index of elements in elements not equal to wx
elements(indexmr)=0;% set values to zero
the problem that there exists values that are not setted to zero and does'nt exist in wx
size(wx)
155 1
size(find(elements))
176 1
i have tried also
elements=zeros(size(T(:,1)));
for j=1: size(elements,1)
for i=1: size(index,1)
if (index(i)==j)
elements(j)=T(index(i),1);
end
end
end
size(find(elements))
115 1
Thnaks in advance

Accepted Answer

Image Analyst
Image Analyst on 9 Jul 2016
Please give some data with desired output. It's not clear what you want.
For example to "set all values different from wx vector to zero" you could do
% Find indexes where labels is different from wx.
indexesThatDontMatch = labels ~= wx;
% Now set to zero.
labels(indexesThatDontMatch) = 0;
Or maybe it's possible you want the setdiff(): "C = setdiff(A,B) returns the data in A that is not in B." I'm not sure until you clarify some more by showing input and output data.

More Answers (0)

Categories

Find more on Cell Arrays in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!