필터 지우기
필터 지우기

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 CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by