Set some values to zero regarding to anothers

2 次查看(过去 30 天)
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

采纳的回答

Image Analyst
Image Analyst 2016-7-9
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Cell Arrays 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by