Borrar filtros
Borrar filtros

Array weirdness

2 visualizaciones (últimos 30 días)
Trader
Trader el 3 de Abr. de 2012
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

Respuesta aceptada

Geoff
Geoff el 3 de Abr. de 2012
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 comentario
Trader
Trader el 3 de Abr. de 2012
Thanks for you help, (end+1,:) cleans things up a bit.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by