From 1e412e1072b2aea9426eec55022bdc932f591868 Mon Sep 17 00:00:00 2001
From: Mauco03 <marco.gaibotti@skywarder.eu>
Date: Sun, 20 Apr 2025 21:36:38 +0200
Subject: [PATCH] [coeff-transport] Improved coefficient generation

---
 classes/@Rocket/Rocket.m   | 11 ++---------
 classes/misc/Coefficient.m |  5 +++--
 2 files changed, 5 insertions(+), 11 deletions(-)

diff --git a/classes/@Rocket/Rocket.m b/classes/@Rocket/Rocket.m
index b904ff4..019b137 100644
--- a/classes/@Rocket/Rocket.m
+++ b/classes/@Rocket/Rocket.m
@@ -171,15 +171,8 @@ classdef Rocket < Config
                     case 'Yes'
                         parserPath = fullfile(mission.msaPath, 'autoMatricesProtub');
                         addpath(genpath(parserPath));
-                        mainAutoMatProtub(obj);
-
-                        obj.coefficients = Coefficient( ...
-                            fullfile(mission.dataPath, 'aeroCoefficients.mat'), ...
-                            coeffName);
-
-                        obj.coefficientsHighAOA = Coefficient( ...
-                            fullfile(mission.dataPath, 'aeroCoefficientsHighAOA.mat'), ...
-                            coeffName);
+                        [obj.coefficients, obj.coefficientsHighAOA] = ...
+                            mainAutoMatProtub(obj);
                     case 'Cancel'
                         error('Rocket creation aborted')
                     otherwise
diff --git a/classes/misc/Coefficient.m b/classes/misc/Coefficient.m
index 4af9ad6..f7eb51b 100644
--- a/classes/misc/Coefficient.m
+++ b/classes/misc/Coefficient.m
@@ -112,7 +112,7 @@ classdef Coefficient
             %   the specified xcg. Dynamic derivatives are included only if
             %   loadDynamic is true.
             
-            if ~obj.isReady, error('Canno interpolate coefficients: check that all dimensions match'); end
+            if ~obj.isReady, error('Cannot interpolate coefficients: check that all dimensions match'); end
 
             coefficients = zeros(11, 1);
             coefficients(1:6) = obj.staticInterpolant(alpha, mach, beta, altitude, airbakes);
@@ -138,11 +138,12 @@ classdef Coefficient
         end
 
         function value = get.static(obj)
+            if isempty(obj.TOTAL), value = []; return; end
             value = obj.TOTAL([1, 3, 5, 6, 9, 13], :, :, :, :, :, 1);
         end
 
         function value = get.dynamic(obj)
-            if ~obj.isDynamic, value = []; return; end
+            if ~obj.isDynamic || isempty(obj.TOTAL), value = []; return; end
             value = obj.TOTAL([7, 10, 11, 14, 15], :, :, :, :, :, :);
         end
 
-- 
GitLab