Probably simple, but can't seem to make it work.

So, tcouple is an N x Rep matrix with numbers inbetween 0 and 50, where the columns represent scenarios. Now, for every scenario I need to get a vector from t=0:tmax. It's hard to explain. I will give an example. Take the first column of tcouple, then if t=0, I need to have the amount of elements of the first column of tcouple which are greater or equal to 0. if t=1, I need to have the amount of elements of the first column of tcouple which are greater or equal to 1. Etc. So every time from the same column.
I managed to create a m-file for that:
for i=1:N
for t=0:tmax
if tcouple(i,1)>=t
Mtmatrix(i,t+1)=1;
else
Mtmatrix(i,t+1)=0;
end
Mt=sum(Mtmatrix);
end
end
Here Mt is the vector from t=0:tmax for scenario 1 (column 1 of tcouple). But now I need to do this for every scenario, so every column of tcouple, and then get a matrix of all the Mt's.
I've been trying to do this, but every time it goes wrong. It's probably easy, but I just don't see how to solve this.
I hope I made my problem clear. Thanks in advance, Marjolein

Answers (2)

Something like,
sum(bsxfun(@ge, tcouple(:,1), 0:tmax))
Or to apply on the full matrix:
N = 30;
REP = 10;
tcouple = randi([0 50],N,REP);
t = 0:max(tcouple(:));
counts = histc(tcouple,t);
counts = flipud(cumsum(flipud(counts)));
Oleg

This question is closed.

Tags

Asked:

on 12 Mar 2011

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!