フィルターのクリア

Nested structure error with definition . please help.

1 回表示 (過去 30 日間)
anush
anush 2017 年 8 月 29 日
編集済み: Stephen23 2017 年 8 月 29 日
function [ struct_data ] = Initialize_Data_Structure( no_turbines, no_towers )
% Initialize_Data_Structure initialises the data structure and fills with dummy data
for ii=1:no_turbines
struct_data.Turbine(ii,1).Name='';
struct_data.Turbine(ii,1).Gear_Ratio=0;
struct_data.Turbine(ii,1).Rotor.Speed=zeros(2,1);
struct_data.Turbine(ii,1).Rotor.Mode_Names=cell(2,1)';
struct_data.Turbine(ii,1).EF_Names={'EF1','EF2'};
struct_data.Turbine(ii,1).EF_Wind_Speed=zeros(2,1);
struct_data.Turbine(ii,1).EF_Rotor_Speed=zeros(2,1);
for jj=1:no_towers
struct_data.Turbine(ii,1).Tower(jj,1).Name= num2str(jj,'Tower %d');
struct_data.Turbine(ii,1).Tower(jj,1).EF_Data= zeros(2,2);
end
end
end
I am getting an error " Undefined function or variable 'no_turbines'." I am trying to create a nested structure. is there something wrong with the approach.

採用された回答

Stephen23
Stephen23 2017 年 8 月 29 日
編集済み: Stephen23 2017 年 8 月 29 日
You cannot run your function by clicking the big green RUN button. Putting that button on the ribbon was the worst design decision ever, and you should ignore that button.
You can call your function by calling it from the command line (or from a script or function), with as many inputs as it requires, something like this:
S = Initialize_Data_Structure(2,3)
I just tried it, and it works perfectly:
>> S = Initialize_Data_Structure(2,3);
>> S.Turbine(1).Gear_Ratio
ans = 0
To learn very basic things, such as how to call functions, you should do the Introductory Tutorials, which are highly recommended for all beginners:

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by