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

 채택된 답변

Guillaume
Guillaume 2014년 12월 12일

1 개 추천

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

Jan Morawietz
Jan Morawietz 2014년 12월 12일
thank you for your quick response!
one additional question:
is there a similiar command for matlab's term structure function, i.e.
StartDates = (MNDate)';
EndDates = (MXDate)';
Rates = (Rates);
Compounding = -1;
Rate_array = intenvset('StartDates', num2cell(StartDates),'EndDates', num2cell(EndDates), 'Rates', num2cell(Rates),'Compounding', Compounding);
unfortunatley the code above does not work
Jan Morawietz
Jan Morawietz 2014년 12월 12일
MNDate and MXDates are vectors with length of 100 days. Rates are given for each date
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 2014년 12월 12일
thank u

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Structures에 대해 자세히 알아보기

태그

질문:

2014년 12월 12일

댓글:

2014년 12월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by