필터 지우기
필터 지우기

Array weirdness

조회 수: 2 (최근 30일)
Trader
Trader 2012년 4월 3일
Hello everyone, I have something very strange happening that I don't understand...
I'm using a for loop to fill an array with values, the first iteration works just fine, the second works correctly but 16 blank rows appear before my second iteration is written. The blank cells have the same number of columns as the first and second. It's only between the first and second row that this happens. Any ideas?
Here's basically what I have gong on:
results.full_data = {};
obsv = 1;
for 20:1:400
... fill struct met that will hold the data going into results.full_data ...
[results] = buildOutput(counter, met, results);
obsv = obsv+1;
end
function[results] = buildOutput(obsv, met, results)
z = length(results.full_data)+1;
results.full_data(z,:) = {met.counter(obsv) met.current_date(obsv) met.current_time(obsv) met.action(obsv) met.position(obsv) met.pa(obsv) met.bp(obsv) met.num_shares(obsv) met.entry_price(obsv) met.price(obsv) met.sma(obsv) met.stdev(obsv) met.t_band(obsv) met.tm_band(obsv) met.l_band(obsv) met.lm_band(obsv) met.profit(obsv)};
end
Any advice you'd be able to give would be greatly appreciated
Thank you

채택된 답변

Geoff
Geoff 2012년 4월 3일
The call to length returns the largest dimension, which in your case is 17. So the first time, you write 1 row, then you write the 18th row. Thus leaving 16 empty rows between.
Instead of length use size(results.full_data,1) to return the number of rows.
Note that you could have dispensed with the 'z' calculation altogether and done this:
results.full_data(end+1,:) = { etc etc etc };
  댓글 수: 1
Trader
Trader 2012년 4월 3일
Thanks for you help, (end+1,:) cleans things up a bit.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by