Borrar filtros
Borrar filtros

Nested structure error with definition . please help.

1 visualización (últimos 30 días)
anush
anush el 29 de Ag. de 2017
Editada: Stephen23 el 29 de Ag. de 2017
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.

Respuesta aceptada

Stephen23
Stephen23 el 29 de Ag. de 2017
Editada: Stephen23 el 29 de Ag. de 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:

Más respuestas (0)

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by