spaceconcordia / rocketry-performance

2 stars 1 forks source link

Can't assign values to multi-dimensional array in Simulink Matlab Function #1

Closed SpaceShawn closed 9 years ago

SpaceShawn commented 9 years ago

In the _dynamic_weightcalculation.m file, an array is zeroed with the correct length to store all the data that will populate it:

weight_curve = zeros(data_length,1);

Then, we loop through it and assign values:

for i = 1:data_length
    weight_curve(i,2) = wet_motor_weight - mfc*thrust_curve(i,1); 
end

The following error messages appear:

 Index expression out of bounds. Attempted to access element 2. The valid range is 1-1.
More information

Function 'Thurst Curve Data/MATLAB Function' (#35.1242.1243), line 31, column 20:
"2"
Launch diagnostic report.
Component: MATLAB Function | Category: Coder errorOpen

 Errors occurred during parsing of MATLAB function 'Thurst Curve Data/MATLAB
Function'(#34)
Component: MATLAB Function | Category: Coder error

 Code Directory :
     "C:\Users\scorpii\Documents\Space\Rocketry\Performance\rocketry-performance\functions\data\slprj\_sfprj\Simplified_Model_test\rocket_dynamic_data_library\sfun\src"

Machine (#23): "rocket_dynamic_data_library"  Target : "sfun"

Chart "MATLAB Function" (#34):

.
Code generation failed Errors occurred during parsing of MATLAB function 'Thurst Curve Data/MATLAB
Function'(#34)


Component: Coder | Category: Coder error

 Library failed to build. Cannot continue build process.
Component: Stateflow | Category: Build error

 Errors occurred during parsing of MATLAB function 'Thurst Curve Data/MATLAB
Function'(#34)
Component: Simulink | Category: Model error
SpaceShawn commented 9 years ago

The problem is related to code generation in Simulink. All steps are followed to my knowledge from this source: http://www.mathworks.com/help/simulink/ug/best-practices-for-defining-variables-for-c-c-code-generation.html

SpaceShawn commented 9 years ago

This occurs because the Matlab Function block interprets an incoming array as a single variable due to incompatibility with mxArray type