Info

This question is closed. Reopen it to edit or answer.

Why do I get a 6x30 matrix instead than a 1031x30

1 view (last 30 days)
PaoloPa
PaoloPa on 23 Feb 2014
Closed: MATLAB Answer Bot on 20 Aug 2021
Hi, I run this code and I got as a result a 6x30 matrix instead than a 1031x30.
Total weeks is long 1052 cells, startweek is 8. orderweeks is 6 cells long, and the result shows only the last 6 rows of the whole period.
for k = startweek:totalweeks-p1-p2-1
start1 = k;
stop1 = start1+p1-1;
orderweeks = start1:stop1;
start2 = stop1+2;
stop2 = start2+p2-1;
holdweeks = start2:stop2;
nstocks = nbrstocks(k);
% order R for the ordering weeks
data1 = stockdata(orderweeks, 1:nstocks);
I am not sure I made myself very clear.... Thanks anyway
PP.
  1 Comment
Walter Roberson
Walter Roberson on 23 Feb 2014
Where is the end of your "for" loop?
As you are in a "for" loop, which variable are you saving results into that is not overwritten by the next iteration of the loop ?

Answers (1)

PaoloPa
PaoloPa on 24 Feb 2014
Ok then I put the whole code..
for k = startweek:totalweeks-1-p1-p2
start1 = k; stop1 = start1+p1-1; orderweeks = start1:stop1;
start2 = stop1+2;
stop2 = start2+p2-1;
holdweeks = start2:stop2;
nstocks = nbrstocks(k);
% order R for the ordering weeks data1 = stockdata(orderweeks, 1:nstocks);
R1 = ones(1,nstocks);
for m = 1:length(orderweeks)
R1 = R1.*data1(m,:);
end
R1 = R1-1;
% select for the winners and losers
[B,idx] = sort(R1,'descend');
ncandidates = round(nstocks*0.1);
idwinner(k,1:ncandidates) = stockid(idx(1:ncandidates));
idloser(k,1:ncandidates) = stockid(idx(end-ncandidates+1:end));
% caculate the R for winners and losers in holding weeks
data2winner = stockdata(holdweeks, idx(1:ncandidates));
data2loser = stockdata(holdweeks, idx(end-ncandidates+1:end));
R2w = ones(1,ncandidates);
R2l = ones(1,ncandidates);
for m = 1:length(holdweeks)
R2w = R2w.*data2winner(m,:);
R2l = R2l.*data2loser(m,:);
end
R2w = R2w-1;
R2l = R2l - 1;
Rwinner(k) = mean(R2w);
Rloser(k) = mean(R2l);
end
end end
  1 Comment
PaoloPa
PaoloPa on 24 Feb 2014
I've been trying this
data1 = stockdata(isfinite(stockdata(orderweeks, :)));
but I stillget bizarre results...like a 180x1 vector.... Any help is very much appreciated mate

Community Treasure Hunt

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

Start Hunting!