iterate structures: Error message

2 visualizaciones (últimos 30 días)
Jan Morawietz
Jan Morawietz el 12 de Dic. de 2014
Comentada: Jan Morawietz el 12 de Dic. de 2014
Can someone please help me with this iteration:
Assumme I have the following components of a strcuture:
field1 = 'FinObj'; value1 = 'StockSpec';
field2 = 'Sigma'; value2 = [1,2,3];
field3 = 'AssetPrice'; value3 = [0.2,0.3,0.2];
I need to create three different structures. The following code is not working:
struct_array=struct([]);
for n = 1:3
struct_array(n) struct(field1,value1,field2,value2(n),field3,value3(n));
end
Thank you for any help! Best Jan

Respuesta aceptada

Guillaume
Guillaume el 12 de Dic. de 2014
field1 = 'FinObj'; value1 = 'StockSpec';
field2 = 'Sigma'; value2 = [1,2,3];
field3 = 'AssetPrice'; value3 = [0.2,0.3,0.2];
s_array = struct(field1, value1, field2, num2cell(value2), field3, num2cell(value3))
  5 comentarios
Guillaume
Guillaume el 12 de Dic. de 2014
I know nothing about the financial toolbox, I'm afraid.
You can always use arrayfun to create a an array from scalars. This should work assuming intenvset returns a structure:
Rate_array = arrayfun(@(sd, ed, r) intenvset('StartDates', sd, 'EndDates', ed, 'Rates', r, 'Compounding', -1), MNDate, MXDate, Rates)
Jan Morawietz
Jan Morawietz el 12 de Dic. de 2014
thank u

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Language Fundamentals 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