Facing some errors during doing the program matlab.

4 visualizzazioni (ultimi 30 giorni)
Questo/a domanda è stato/a segnalato/a da Dyuman Joshi
function [residus, Stat, coefficients] = Calcul_Coef_NEW(SN, type, table_pression_kPa, P, T, degree)
degree = input('Enter the degree of the polynomial: ');
table_pression_psi = table_pression_kPa * 0.145038;
% Fit the polynomial curve based on the specified degree
%fitting_type = ['poly', num2str(degree)];
fitting_type = ['poly', num2str(degree)];
data_matrix = [T(:), P(:)];
FCT_COR = fit(data_matrix, table_pression_psi', fitting_type);
%a='poly32';
%[FCT_COR,GOF,OUTPUT] = fit([T, P], table_pression_psi, fitting_type);
% Calculate the residuals
%residuals = table_pression_psi - FCT_COR(T', P');
residuals = table_pression_psi - FCT_COR(T(:), P(:));
%residuals2=OUTPUT.residuals;
% Calculate the maximum and average residuals
Res_max = max(abs(residuals));
Res_moy = mean(abs(residuals));
SYNTH_RES{1, 1} = 'SN Capteur';
SYNTH_RES{2, 3} = 'P';
SYNTH_RES{1, 4} = 'Résidu max';
SYNTH_RES{1, 5} = 'Résidu moy';
SYNTH_RES{1, 6} = 'R²';
SYNTH_RES{1, 7} = 'Erreur standard (psi)';
SYNTH_RES{2, 1} = SN;
SYNTH_RES{2, 4} = Res_max;
SYNTH_RES{2, 5} = Res_moy;
%SYNTH_RES{2, 6} = NaN;
%SYNTH_RES{2, 7} = NaN;
SYNTH_RES{2,6}=GOF.rsquare;
SYNTH_RES{2,7}=GOF.rmse;
% Write the coefficients
coefficients = coeffvalues(FCT_COR);
for m = 1:length(coefficients)
SYNTH_RES{m+4, 1} = ['a', num2str(m-1)];
SYNTH_RES{m+4, 2} = coefficients(m);
end
SYNTH_RES{length(coefficients)+6, 1} = 'Pression banc (psi)';
SYNTH_RES{length(coefficients)+6, 2} = 'Pression banc (kPa)';
SYNTH_RES{length(coefficients)+6, 3} = 'Température (°C)';
SYNTH_RES{length(coefficients)+6, 4} = 'Ratio';
SYNTH_RES{length(coefficients)+6, 5} = 'Residu (psi)';
SYNTH_RES{length(coefficients)+6, 6} = 'Residu (kPa)';
SYNTH_RES{length(coefficients)+6, 7} = 'Pression corrigée (psi)';
SYNTH_RES{length(coefficients)+6, 8} = 'Pression corrigée (kPa)';
% Write the data (P reference, temperature, ratio, residuals, P0) in psi & kPa
for i = 1:length(table_pression_psi)
SYNTH_RES{length(coefficients)+6+i, 1} = table_pression_psi(i);
SYNTH_RES{length(coefficients)+6+i, 2} = table_pression_kPa(i);
SYNTH_RES{length(coefficients)+6+i, 3} = T(i);
SYNTH_RES{length(coefficients)+6+i, 4} = P(i);
SYNTH_RES{length(coefficients)+6+i, 5} = OUTPUT.residuals(i);
SYNTH_RES{length(coefficients)+6+i, 6} = OUTPUT.residuals(i)*6.894757;
SYNTH_RES{length(coefficients)+6+i, 7} = FCT_COR(T(i),P(i));
SYNTH_RES{length(coefficients)+6+i, 8} = FCT_COR(T(i),P(i))*6.894757;
%SYNTH_RES{length(coefficients)+6+i, 9} = residuals_p32(i);
%SYNTH_RES{length(coefficients)+6+i, 10} = residuals_p32(i) * 6.894757;
%SYNTH_RES{length(coefficients)+6+i, 11} = FCT_COR_p32(T(i));
%SYNTH_RES{length(coefficients)+6+i, 12} = FCT_COR_p32(T(i)) * 6.894757;
end
xlswrite(fullfile('.\results\Poly', strcat('SN', SN, '_synthese.xlsx')), SYNTH_RES, type);
residus = cat(2, residuals);
Stat(1, 1) = Res_max * 6.894757;
Stat(2, 1) = Res_moy * 6.894757;
%Stat(3, 1) = NaN;
%Stat(4, 1) = NaN;
%Stat(1, 2) = Res_max_p32 * 6.894757;
%Stat(2, 2) = Res_moy_p32 * 6.894757;
%Stat(3, 2) = NaN;
%Stat(4, 2) = NaN;
Stat(3,1)= GOF.rsquare;
Stat(4,1)= GOF.rmse*6.894757;
end
2nd program :
function [RES] = extract_palier_P0_P21_P32_montant_descendant_NEW(SN,titre, table_delete,SW_version)
%extract_palier_P0_P21_P32_montant_descendant that takes four input arguments:
%SN, titre, table_delete, and SW_version
formatOut='yyyymmddTHHMM';
Datejour=datestr(now,formatOut);
%SN = 'Palier';
%Datejour = num2str(datetime('today'),'yyyymmdd');
SN=strcat(SN,'_',Datejour);
%saisir le SN du capteur
table_pression_kpa=[... %saisir manuellement les paliers de pression du banc, dans l'ordre ou ils ont été effectués
100; 80; 60; 40; 20; 10;30; 50; 70; 90; 120;...
100; 80; 60; 40; 20; 10;30; 50; 70; 90; 120;...
100; 80; 60; 40; 20; 10;30; 50; 70; 90; 120;...
100; 80; 60; 40; 20; 10;30; 50; 70; 90; 120;...
100; 80; 60; 40; 20; 10;30; 50; 70; 90; 120;...
100; 80; 60; 40; 20; 10;30; 50; 70; 90; 120 ];
% AJUSTER LES PALIERS DE PRESSION AVEC LA VARIATION DE PATM
% PENDANT LES PALIERS
table_pression_psi=table_pression_kpa*0.145038;
%load('Pbanc.mat')
% load('Pbanc_sans60degres.mat')
% table_pression_psi=Pbanc_abs_comp;
% supprimer manuellement les paliers/points qui ne nous interessent pas, ainsi que les transitions (la détection de stabilité ne marche pas très bien).
% Format : [début_plage_suppr1 fin_plage_suppr1 ; début_plage_suppr2 fin_plage_suppr2]
%saisir manuellement le chemin du log à analyser
%titre='C:\Users\F528245\Desktop\Matlab_Etienne\P0\Data\capteur2124001.txt';
%table_delete=[1 583;595 607;619 630;642 654;666 678;690 702;714 726;738
%750;762 774;786 798;810 822;834 1419;1431 1442;1454 1466;1478 1490;1502
%1514;1526 1538;1550 1562;1574 1586;1598 1610;1622 1634;1646 1657;1669
%2254;2266 2278;2290 2302;2314 2326;2338 2350;2362 2374;2386 2398;2410
%2422;2434 2446;2458 2469;2481 2493;2505 3090;3102 3114;3126 3138;3150 3162;3174 3186;3198 3210;3222 3234;3246 3258;3270 3282;3294 3305;3317 3328;3340 3926;3938 3950;3962 3974;3986 3998;4010 4022;4034 4046;4058 4072;4084 4094;4106 4117;4129 4141;4153 4165;4177 4761;4773 4786;4798 4810;4822 4834;4846 4858;4870 4882;4894 4905;4917 4929;4941 4953;4965 4977;4989 5001;5013 10000];
%% data extract
[data,temp]=detect_palier_P0(titre,table_delete,SN,SW_version);
%% extraction des paliers
n_palier=ones(1,length(data));
current_palier=1;
indice_palier(1,1)=1;
%origine : seuil_palier=5000/8388607; %5000 LSB comparés à 2^23=8388607 --> si deux échantillons successifs ont au moins cet écart, on est sur un nouveau palier.
%for i=2:length(data)
% if (data(i)>data(i-1)+seuil_palier) || (data(i)<data(i-1)-seuil_palier)
% current_palier=current_palier+1;
% indice_palier(current_palier-1,2)=i-1;
% indice_palier(current_palier,1)=i;
% end
% n_palier(i)=current_palier;
%end
seuil_palier_P=5000/8388607;
%Ajout de condition sut la température pour le cahngement de palier (10°C)
seuil_palier_T=10;
for i=2:length(data)
%25/20/2021 Eetienne; mise en commetaire opour corriger pb dettection palier if ((data(i)>data(i-1)+seuil_palier_P) || (data(i)<data(i-1)-seuil_palier_P))
if ((data(i)>data(i-1)+seuil_palier_P) || (data(i)<data(i-1)-seuil_palier_P) || ...
((temp(i)>temp(i-1)+seuil_palier_T) || (temp(i)<temp(i-1)-seuil_palier_T)))
current_palier=current_palier+1;
indice_palier(current_palier-1,2)=i-1;
indice_palier(current_palier,1)=i;
end
n_palier(i)=current_palier;
end
nb_palier=max(n_palier);
indice_palier(nb_palier,2)=length(data);
%% Palier moyenné sur la plage stable et calcul d'indicateurs statistiques sur la plage stable
%% Averaged level over the stable range and calculation of statistical indicators over the stable range
% This code is used to process data that contains stable ranges of values and calculate various statistical indicators for these ranges.
%The stable ranges are defined by the "indice_palier" array,
%which contains the start and end indices of each range.
%"data" array between the two indices "indice_palier(i,1)" and "indice_palier(i,2)",
%and assigns this mean value to the "i-th" row and first column of the "palier_extract" array
for i=1:nb_palier
palier_extract(i,1)=mean(data(indice_palier(i,1):indice_palier(i,2))); % pression moyenne
palier_extract(i,2)=mean(temp(indice_palier(i,1):indice_palier(i,2))); % température moyenne
palier_extract(i,3)=std(data(indice_palier(i,1):indice_palier(i,2))); % ecart type sur le ratio (en V/V):::standard deviation on the ratio convert it from volts per volt (V/V) to least significant bits (LSB),
palier_extract(i,4)=std(data(indice_palier(i,1):indice_palier(i,2)))*8388608; % ecart type sur le ratio (en LSB)least significant bit
palier_extract(i,5)=std(temp(indice_palier(i,1):indice_palier(i,2))); % ecart type sur la température (en °C):::standard deviation on the temparature
%This provides an estimate of the amount of variation or noise in the
%temperature over each stable range.
end
%% Fit
%perform a polynomial fit on the data contained in the "palier_extract" array.
%The "fit" function is called with three input arguments: [T,alpha], P, and 'polytype'
%the "fit" function is likely being used to fit a polynomial function of "T" and "alpha" to the pressure data "P".
%extracts the second column (index 2) of the "palier_extract" array and assigns it to a variable called "T".
%[FCT_COR,GOF,OUTPUT]=fit([T,alpha],P,'polytype')
%the notation (:,2) is used to select all rows in the second column of a 2D array or matrix.
T=palier_extract(:,2); % temperature
P=palier_extract(:,1); % pression
%% Definition des P & T quand T descend
for t = 12:55
T_descendant(t-11,1)=palier_extract(t,2);
P_descendant(t-11,1)=palier_extract(t,1);
table_pression_kPa_descendant(t-11,1)= table_pression_kpa(t);
end
%% Definition des P & T quand T monte
%two arrays T_montant and P_montant based on the data in palier_extract,
%as well as a third array table_pression_kPa_montant
%t = 1 to t = 22 and extracts data from the first 22 rows of palier_extract
%into the T_montant and P_montant arrays.
%The table_pression_kPa_montant array is also assigned the corresponding value from the table_pression_kpa array for each row.
for t = 1:22
T_montant(t,1)=palier_extract(t,2);
P_montant(t,1)=palier_extract(t,1);
table_pression_kPa_montant(t,1)= table_pression_kpa(t);
end
%extracts data from the 45th to 66th rows of palier_extract
%the code subtracts 22 from t and uses that value as the index in the T_montant and P_montant arrays. This effectively starts assigning values to these arrays at index 23,
%so that the data from the second for loop is appended to the data from the first for loop
for t = 45:66
T_montant(t-22,1)=palier_extract(t,2);
P_montant(t-22,1)=palier_extract(t,1);
table_pression_kPa_montant(t-22,1)= table_pression_kpa(t);
%instead of using the index t, the code subtracts 22 from t and uses that value as the index in the T_montant and P_montant arrays.
%This effectively starts assigning values to these arrays at index 23,
end
%Calcul des coeff des polynomes p21 & p32
%pressure and temperature measurements at different levels.
%[residus_montant,Stat_montant] = Calcul_Coef_NEW(SN,'montant',table_pression_kPa_montant,P_montant,T_montant);
%[residus_descendant,Stat_descendant] = Calcul_Coef_21_32(SN,'descendant',table_pression_kPa_descendant,P_descendant,T_descendant);
%calculates the coefficients for a third scenario, labeled "full", which likely refers to the entire data set
[residus_full,Stat_full] = Calcul_Coef_NEW(SN,'full',table_pression_kpa,P,T,degree);
3rd program :
clear
clc
close all
Res = extract_palier_P0_P21_P32_montant_descendant_NEW('SN2124009_Calib_2022-04-07','C:\Users\FX625040\Documents\Stage\Scripts Matlab\P0\capteur2125011.txt',...
[1 594;606 618;630 642;654 666;678 690;702 714;726 738;750 762;774 786;798 809;821 833;845 1430;1442 1454;1466 1478;1490 1502;1514 1525;1537 1549;1561 1573;1585 1597;1609 1621;1633 1645;1657 1669;1681 2265;2277 2289;2301 2313;2325 2337;2349 2361;2373 2385;2397 2409;2421 2433;2445 2457;2469 2480;2492 2504;2516 3101;3113 3125;3137 3149;3161 3173;3185 3197;3209 3221;3233 3244;3256 3268;3280 3292;3304 3316;3328 3340;3352 3937;3949 3960;3972 3984;3996 4008;4020 4032;4044 4056;4068 4080;4092 4104;4116 4128;4140 4151;4163 4175;4187 4772;4784 4796;4808 4820;4832 4844;4856 4868;4880 4892;4904 4915;4927 4939;4951 4963;4975 4987;4999 5011;5023 10000],...
1);
i have also 4th program and 5 th program but i think here it is not needed to solve the errors ........
...................................................................................................................................... here are the errors :
Undefined function or variable 'degree'.
Error in extract_palier_P0_P21_P32_montant_descendant_NEW (line 138)
[residus_full,Stat_full] = Calcul_Coef_NEW(SN,'full',table_pression_kpa,P,T,degree);
Error in autom_P0_montant_descendant_NEW (line 4)
Res =
extract_palier_P0_P21_P32_montant_descendant_NEW('SN2124009_Calib_2022-04-07','C:\Users\FX625040\Documents\Stage\Scripts
Matlab\P0\capteur2125011.txt',...

Risposte (1)

Cris LaPierre
Cris LaPierre il 1 Giu 2023
The first line of the error message gives you the root cause: Undefined function or variable 'degree'.
At the bottom of your second program (function named Calcul_Coef_NEW) you have the line of code
[residus_full,Stat_full] = Calcul_Coef_NEW(SN,'full',table_pression_kpa,P,T,degree)
However, degree is never defined inside this function, and it is not passed into the function as an input argument, ergo your error. See here for more: https://www.mathworks.com/help/matlab/matlab_prog/base-and-function-workspaces.html

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by