incI=zeros(length(featInd),length(tempInd));
for f = 1:length(featInd)
incI(f,:) = tempInd + featInd(f);
end
for k=1:length(featInd)
h([incI(k,:)]') = h([incI(k,:)]')+ 1;
end

2 Comments

jgg
jgg on 26 Jan 2016
You need to provide more information. What is h? What is featInd? What is tempInd? How are they structured?
featInd=[1,24636] row vector
tempInd=[1,12332] row vector
h=[14593760,1] coloumn vector

Sign in to comment.

 Accepted Answer

Honglei Chen
Honglei Chen on 26 Jan 2016
Edited: Honglei Chen on 26 Jan 2016
Here is an example you can try
featInd = 1:24636;
tempInd = 1:12332;
incI = bsxfun(@plus,featInd(:),tempInd);
As to the second loop, I could be wrong but that looks just like a histogram for me, so you can probably do something like
[incU,~,incInd] = unique(incI(:),'stable');
h = zeros(14593760,1);
h(incU) = h(incU)+accumarray(incInd,ones(numel(incInd),1));

2 Comments

Updated the code with correct dimension, although the dimension of h may depend on what you have in featInd and tempInd
Thanks Honglei Chen tried your approach for second loop. Works for smaller values of tempInd & featInd. For large values unique function gives out of memory error when executed on GPU.

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!