trying to fill a matrix with threshold data

1 Ansicht (letzte 30 Tage)
DuckDuck
DuckDuck am 7 Jun. 2012
my problem is simple i'm running a threshold through loop, and i want to store the idx in a matrix where each column represent the values after threshold. but because the amount of values in each column is not the same i'm facing the problem of indexing. my code looks like this
for (p=0.6:0.001:1.7); %threshold range
x1=find(x>p); %threshold value
cid=((p*1000)-5999); %trying to index
x2(:,cid)=x(x1); %trying to put threshold values to each column
end;

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 7 Jun. 2012
t = bsxfun(@times,bsxfun(@gt,x,p),x);
x2 = arrayfun(@(ii)nonzeros(t(:,ii)),1:size(t,2),'un',0);
EDIT
out = bsxfun(@times,bsxfun(@gt,x,p),x)
or
out = bsxfun(@times,bsxfun(@gt,x,p),p)
  1 Kommentar
DuckDuck
DuckDuck am 7 Jun. 2012
ok this is a cleaner and better way to write it, but i still don't get the columns for each threshold i apply??

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by