Clear Filters
Clear Filters

Nested structure error with definition . please help.

1 view (last 30 days)
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.

Accepted Answer

Stephen23
Stephen23 on 29 Aug 2017
Edited: Stephen23 on 29 Aug 2017
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:

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!