From 96459e2b8f05314f30054bee9a971b9dfe17225b Mon Sep 17 00:00:00 2001 From: Pengtao Xie Date: Thu, 4 Jan 2024 21:11:59 +0100 Subject: [PATCH] PT: plot to compare. Add Median und Mode --- scripts/similarities.m | 2 +- scripts/similarities2.m | 86 +++++++++++++++++++++++++++-------------- 2 files changed, 57 insertions(+), 31 deletions(-) diff --git a/scripts/similarities.m b/scripts/similarities.m index 84def03..a164687 100644 --- a/scripts/similarities.m +++ b/scripts/similarities.m @@ -1,6 +1,6 @@ %% please open Magic Formular APP first clear -n = 20 +n = 20; mkdir('similarityData'); %% directoryPath = "..\sorted_data"; diff --git a/scripts/similarities2.m b/scripts/similarities2.m index 28f90b8..baabba9 100644 --- a/scripts/similarities2.m +++ b/scripts/similarities2.m @@ -12,47 +12,73 @@ fileNames = {files.name}; for n=1:length(fileNames) % fit the curve of 43075 , 8 inch filePath = fullfile(directoryPath, fileNames(n)); - load(filePath) + load(filePath); [fitresult, gof] = createFit(SAA{8},FYY{8}); - residual = []; - % Evaluate the fitted curves - for i=1:length(SAA) - y_fit = fitresult(SAA{i}); + for tire=1:length(SAA) + y_fit = fitresult(SAA{tire}); % Calculate residuals - residual = [residual, mean(abs(FYY{i} - y_fit))]; + residuals{tire}{n} = abs(FYY{tire} - fitresult(SAA{tire})); end - residuals{n} = residual; end -for i=1:length(residual) - residuals_sum{i} = 0; - num = length(fileNames); - for j=1:length(fileNames) - if isnan(residuals{j}(i)) - num = num - 1; - residuals{j}(i) = 0; - end - residuals_sum{i} = residuals{j}(i) + residuals_sum{i}; +for tire=1:length(SAA) + residuals_one_tire = []; + for n=1:length(fileNames) + residuals_one_tire = [residuals_one_tire; residuals{tire}{n}]; end - residuals_mean{i} = residuals_sum{i}/num; + residuals_tire{tire} = residuals_one_tire; end -% figure() -% idx = linspace(1,length(SAA),length(SAA)); -% for i=1:length(fileNames) -% plot(idx, residuals{i}, "-*") -% hold on; -% end -% title("Residuials") -% legend(fileNames) -% xlabel("order of the tires(8 is our traget tire)") +%% mean +for tire=1:length(SAA) + num = 0; + % each tire under 60 measurement conditions + for i=1:length(residuals_tire{tire}) + if not(isnan(residuals_tire{tire}(i))) + num = num + 1; + else + residuals_tire{tire}(i) = 0; + end + end + residuals_mean{tire} = sum(residuals_tire{tire})/num; +end +%% median +for tire=1:length(SAA) + residuals_median{tire} = median(residuals_tire{tire}); +end +%% mode +for tire=1:length(SAA) + residuals_mode{tire} = mode(residuals_tire{tire}); +end + +%% plots +idx = linspace(1,length(SAA),length(SAA)); figure() -idx = linspace(1,length(SAA),length(SAA)); -y = cell2mat(residuals_mean) +subplot(311) +y = cell2mat(residuals_mean); plot(idx, y, "-*") title("Average Absolute Residuials") -legend(fileNames) -xlabel("order of the tires(8 is our traget tire)") +xlabel("Order of the tires(8 is our traget tire)") +ylabel("in 1") +xticks(idx) +grid on + +subplot(312) +y = cell2mat(residuals_median); +plot(idx, y, "-o") +title("Median of the Absolute Residuials") +xlabel("Order of the tires(8 is our traget tire)") +ylabel("in 1") +xticks(idx) +grid on + + +subplot(313) +y = cell2mat(residuals_mode); +plot(idx, y, "-o") +title("Mode of the Absolute Residuials") +xlabel("Order of the tires(8 is our traget tire)") +ylabel("in 1") xticks(idx) grid on \ No newline at end of file