Standard deviation error bars for each interpolated value of temperature

4 次查看(过去 30 天)
I am trying to produce standard deviation error bars for the interpolated data ranging from 10 to 35 degrees with a a 1 degree interval, being plotted on the averaged interpolated data line. However, I can't seem to produce seperate standard deviations for each of the interpolated temperatures.
Below is the code I have used for one of the 4 oils.
Oilviscositytest10cst = readmatrix('Oil viscosity test 10cst.xlsx','Range','A6:O65');
xq = linspace(10,35,25);
% 10 cSt oil
% run 1
figure(1)
% run 1 ramp up
temp_1_rup_10 = Oilviscositytest10cst(2:27,3);
viscosity_1_rup_10 = Oilviscositytest10cst(2:27,5);
vq_1_up_10 = interp1(temp_1_rup_10,viscosity_1_rup_10,xq);
plot(xq,vq_1_up_10,'r')
hold on
plot(temp_1_rup_10,viscosity_1_rup_10,'ko')
title('10 cSt oil')
% run 1 ramp down
temp_1_rdown_10 = Oilviscositytest10cst(35:60,3);
viscosity_1_rdown_10 = Oilviscositytest10cst(35:60,5);
vq_1_down_10 = interp1(temp_1_rdown_10,viscosity_1_rdown_10,xq);
plot(xq,vq_1_down_10,'b')
hold on
plot(temp_1_rdown_10,viscosity_1_rdown_10,'ko')
% run 2
% run 2 ramp up
temp_2_rup_10 = Oilviscositytest10cst(2:27,11);
viscosity_2_rup_10 = Oilviscositytest10cst(2:27,13);
vq_2_up_10 = interp1(temp_2_rup_10,viscosity_2_rup_10,xq);
plot(xq,vq_2_up_10,'c')
hold on
plot(temp_2_rup_10,viscosity_2_rup_10,'ko')
% run 2 ramp down
temp_2_rdown_10 = Oilviscositytest10cst(35:60,11);
viscosity_2_rdown_10 = Oilviscositytest10cst(35:60,13);
vq_2_down_10 = interp1(temp_2_rdown_10,viscosity_2_rdown_10,xq);
plot(xq,vq_2_down_10,'g')
hold on
plot(temp_2_rdown_10,viscosity_2_rdown_10,'ko')
% run 3
% run 3 ramp up
temp_3_rup_10 = Oilviscositytest10cst(2:27,3);
viscosity_3_rup_10 = Oilviscositytest10cst(2:27,5);
vq_3_up_10 = interp1(temp_3_rup_10,viscosity_3_rup_10,xq);
plot(xq,vq_3_up_10,'r')
hold on
plot(temp_3_rup_10,viscosity_3_rup_10,'ko')
% run 3 ramp down
temp_3_rdown_10 = Oilviscositytest10cst(35:60,3);
viscosity_3_rdown_10 = Oilviscositytest10cst(35:60,5);
vq_3_down_10 = interp1(temp_3_rdown_10,viscosity_3_rdown_10,xq);
plot(xq,vq_3_down_10,'b')
hold on
plot(temp_3_rdown_10,viscosity_3_rdown_10,'ko')
% average viscosity
six = 6*(ones(1,1));
addition_vq_10 = vq_1_up_10 + vq_1_down_10 + vq_2_up_10 + vq_2_down_10 + vq_3_up_10 + vq_3_down_10;
average_vq_10 = addition_vq_10/six;
plot(xq,average_vq_10,'k')
plot(xq, average_vq_10, 'ko')
err_10 = (std(average_vq_10,[],2)/sqrt(size(average_vq_10,2)))
err_10 = 0.2498
e_10 = errorbar(xq,average_vq_10,err_10);
figure(2)
plot(xq,average_vq_10,'m')
hold on
plot(xq, average_vq_10, 'ko')

回答(2 个)

Torsten
Torsten 2023-12-16
You mean the graphics if you add the line
errorbar(xq,average_vq_10,err_10,"blue")
at the end of your code from above ?
  9 个评论
Daniel Jackson
Daniel Jackson 2023-12-16
I've tried that code and the error message "Unrecognized function or variable 'i'." occurs
Torsten
Torsten 2023-12-17
编辑:Torsten 2023-12-17
It seems we computed the same.
But still I'm not convinced whether it's statistically correct to interpolate the six experiments to equal values of temperature and then compute errorbars for the interpolated values.
Oilviscositytest10cst = readmatrix('Oil viscosity test 10cst.xlsx','Range','A6:W65');
xq = linspace(10,35,25);
% 10 cSt oil
% run 1
figure(1)
% run 1 ramp up
temp_1_rup_10 = Oilviscositytest10cst(2:27,3);
viscosity_1_rup_10 = Oilviscositytest10cst(2:27,5);
vq_1_up_10 = interp1(temp_1_rup_10,viscosity_1_rup_10,xq);
plot(xq,vq_1_up_10,'r')
hold on
plot(temp_1_rup_10,viscosity_1_rup_10,'ko')
title('10 cSt oil')
% run 1 ramp down
temp_1_rdown_10 = Oilviscositytest10cst(35:60,3);
viscosity_1_rdown_10 = Oilviscositytest10cst(35:60,5);
vq_1_down_10 = interp1(temp_1_rdown_10,viscosity_1_rdown_10,xq);
plot(xq,vq_1_down_10,'b')
hold on
plot(temp_1_rdown_10,viscosity_1_rdown_10,'ko')
% run 2
% run 2 ramp up
temp_2_rup_10 = Oilviscositytest10cst(2:27,11);
viscosity_2_rup_10 = Oilviscositytest10cst(2:27,13);
vq_2_up_10 = interp1(temp_2_rup_10,viscosity_2_rup_10,xq);
plot(xq,vq_2_up_10,'c')
hold on
plot(temp_2_rup_10,viscosity_2_rup_10,'ko')
% run 2 ramp down
temp_2_rdown_10 = Oilviscositytest10cst(35:60,11);
viscosity_2_rdown_10 = Oilviscositytest10cst(35:60,13);
vq_2_down_10 = interp1(temp_2_rdown_10,viscosity_2_rdown_10,xq);
plot(xq,vq_2_down_10,'g')
hold on
plot(temp_2_rdown_10,viscosity_2_rdown_10,'ko')
% run 3
% run 3 ramp up
temp_3_rup_10 = Oilviscositytest10cst(2:27,19);
viscosity_3_rup_10 = Oilviscositytest10cst(2:27,21);
vq_3_up_10 = interp1(temp_3_rup_10,viscosity_3_rup_10,xq);
plot(xq,vq_3_up_10,'r')
hold on
plot(temp_3_rup_10,viscosity_3_rup_10,'ko')
% run 3 ramp down
temp_3_rdown_10 = Oilviscositytest10cst(35:60,19);
viscosity_3_rdown_10 = Oilviscositytest10cst(35:60,21);
vq_3_down_10 = interp1(temp_3_rdown_10,viscosity_3_rdown_10,xq);
plot(xq,vq_3_down_10,'b')
hold on
plot(temp_3_rdown_10,viscosity_3_rdown_10,'ko')
% average viscosity
addition_vq_10 = vq_1_up_10 + vq_1_down_10 + vq_2_up_10 + vq_2_down_10 + vq_3_up_10 + vq_3_down_10;
average_vq_10 = addition_vq_10/6;
err_10 = sqrt(((vq_1_down_10-average_vq_10).^2 +...
(vq_1_up_10-average_vq_10).^2+...
(vq_2_down_10-average_vq_10).^2 +...
(vq_2_up_10-average_vq_10).^2+...
(vq_3_down_10-average_vq_10).^2+...
(vq_3_up_10-average_vq_10).^2)/5);
figure(2)
plot(xq,average_vq_10,'m')
hold on
plot(xq, average_vq_10, 'ko')
errorbar(xq,average_vq_10,err_10);

请先登录,再进行评论。


Star Strider
Star Strider 2023-12-16
编辑:Star Strider 2023-12-17
It is difficult to follow your code, so I created my own based on my best guess as to what you want.
Try this —
% readcell('Oil viscosity test 10cst.xlsx')
% opts = spreadsheetImportOptions('VariableNamesRange','A2:W2', 'VariableUnitsRange','B6:W6', 'VariableNamingRule','preserve')
T1 = readtable('Oil viscosity test 10cst.xlsx', 'VariableNamingRule','preserve')
T1 = 60×23 table
Point No. Time Temperature Shear Stress Viscosity Torque Status Var8 Point No._1 Time_1 Temperature_1 Shear Stress_1 Viscosity_1 Torque_1 Status_1 Var16 Point No._2 Time_2 Temperature_2 Shear Stress_2 Viscosity_2 Torque_2 Status_2 _________ _____ ___________ ____________ _________ _______ ___________ ____ ___________ ______ _____________ ______________ ___________ ________ ___________ _____ ___________ ______ _____________ ______________ ___________ ________ ___________ NaN NaN NaN NaN NaN NaN {0×0 char } NaN NaN NaN NaN NaN NaN NaN {0×0 char } NaN NaN NaN NaN NaN NaN NaN {0×0 char } 1 0.333 10 2.2877 11.441 0.12939 {'Dy_auto'} NaN 1 0.333 9.9 2.3499 11.752 0.13291 {'Dy_auto'} NaN 1 0.333 9.9 0.58291 11.661 0.032968 {'Dy_auto'} 2 0.667 10.78 2.2549 11.275 0.12753 {'Dy_auto'} NaN 2 0.667 10.71 2.3266 11.634 0.13159 {'Dy_auto'} NaN 2 0.667 10.72 0.575 11.501 0.032521 {'Dy_auto'} 3 1 11.79 2.2244 11.122 0.12581 {'Dy_auto'} NaN 3 1 11.73 2.2859 11.43 0.12929 {'Dy_auto'} NaN 3 1 11.74 0.56589 11.318 0.032005 {'Dy_auto'} 4 1.333 12.85 2.1774 10.887 0.12315 {'Dy_auto'} NaN 4 1.333 12.81 2.2371 11.186 0.12653 {'Dy_auto'} NaN 4 1.333 12.82 0.5541 11.082 0.031339 {'Dy_auto'} 5 1.667 13.91 2.1301 10.65 0.12047 {'Dy_auto'} NaN 5 1.667 13.9 2.1851 10.925 0.12358 {'Dy_auto'} NaN 5 1.667 13.89 0.54295 10.859 0.030708 {'Dy_auto'} 6 2 14.97 2.0879 10.439 0.11808 {'Dy_auto'} NaN 6 2 14.96 2.1448 10.724 0.1213 {'Dy_auto'} NaN 6 2 14.95 0.53163 10.633 0.030068 {'Dy_auto'} 7 2.333 16.01 2.0485 10.242 0.11586 {'Dy_auto'} NaN 7 2.333 16.01 2.0986 10.493 0.11869 {'Dy_auto'} NaN 7 2.333 16 0.5213 10.426 0.029484 {'Dy_auto'} 8 2.667 17.04 2.0123 10.061 0.11381 {'Dy_auto'} NaN 8 2.667 17.05 2.0534 10.267 0.11614 {'Dy_auto'} NaN 8 2.667 17.03 0.50957 10.191 0.02882 {'Dy_auto'} 9 3 18.06 1.9715 9.8573 0.1115 {'Dy_auto'} NaN 9 3 18.07 2.0176 10.088 0.11411 {'Dy_auto'} NaN 9 3 18.06 0.49942 9.9885 0.028246 {'Dy_auto'} 10 3.333 19.08 1.9365 9.6824 0.10952 {'Dy_auto'} NaN 10 3.333 19.09 1.9807 9.9033 0.11202 {'Dy_auto'} NaN 10 3.333 19.08 0.49135 9.827 0.02779 {'Dy_auto'} 11 3.667 20.09 1.9012 9.5058 0.10753 {'Dy_auto'} NaN 11 3.667 20.1 1.9439 9.7196 0.10994 {'Dy_auto'} NaN 11 3.667 20.09 0.48154 9.6309 0.027235 {'Dy_auto'} 12 4 21.12 1.8679 9.3396 0.10564 {'Dy_auto'} NaN 12 4 21.11 1.9082 9.5409 0.10792 {'Dy_auto'} NaN 12 4 21.12 0.47284 9.4568 0.026743 {'Dy_auto'} 13 4.333 22.13 1.8342 9.1709 0.10374 {'Dy_auto'} NaN 13 4.333 22.12 1.8721 9.3607 0.10588 {'Dy_auto'} NaN 13 4.333 22.13 0.46581 9.3162 0.026345 {'Dy_auto'} 14 4.667 23.14 1.8071 9.0355 0.10221 {'Dy_auto'} NaN 14 4.667 23.11 1.8464 9.2318 0.10443 {'Dy_auto'} NaN 14 4.667 23.13 0.45763 9.1526 0.025882 {'Dy_auto'} 15 5 24.14 1.7729 8.8647 0.10027 {'Dy_auto'} NaN 15 5 24.13 1.811 9.0549 0.10242 {'Dy_auto'} NaN 15 5 24.13 0.44973 8.9946 0.025436 {'Dy_auto'}
Mv = all(ismissing(T1(:,1:5)),2);
T1(Mv,:) = [];
ColIdx = [1 3 5] + [0; 8; 16]
ColIdx = 3×3
1 3 5 9 11 13 17 19 21
xq = linspace(10,35,25); % Temperature Vector For Interpolation
for k = 1:size(ColIdx,1)
% k
idx = cumsum([true; diff(T1{:,ColIdx(k,1)})<0]);
TempVisc = accumarray(idx, (1:numel(idx)).', [], @(x){[T1{x,ColIdx(k,2)} T1{x,ColIdx(k,3)}]}); % Accumulate Results
% TempVisc
Temp{k} = [TempVisc{1}(:,1) flipud(TempVisc{2}(:,1))];
Visc{k} = [TempVisc{1}(:,2) flipud(TempVisc{2}(:,2))]; % unique Values For Interpolation
Viscic{k,1} = interp1(Temp{k}(:,1), Visc{k}(:,1), xq(:)); % Interpolate
Viscic{k,2} = interp1(Temp{k}(:,2), Visc{k}(:,2), xq(:));
end
Temp
Temp = 1×3 cell array
{26×2 double} {26×2 double} {26×2 double}
Visc
Visc = 1×3 cell array
{26×2 double} {26×2 double} {26×2 double}
Viscic
Viscic = 3×2 cell array
{25×1 double} {25×1 double} {25×1 double} {25×1 double} {25×1 double} {25×1 double}
Visci = cell2mat(reshape(Viscic, 1, []))
Visci = 25×6
11.4410 11.7374 11.6415 11.6115 11.5984 11.4241 11.2354 11.5677 11.4433 11.4035 11.3656 11.2047 11.0570 11.3502 11.2430 11.1709 11.1697 10.9778 10.8255 11.1106 11.0184 10.9674 10.9653 10.7750 10.5989 10.8744 10.8000 10.7581 10.7561 10.5899 10.3939 10.6694 10.5821 10.5267 10.5238 10.3743 10.1998 10.4408 10.3690 10.3228 10.3197 10.1738 10.0107 10.2246 10.1396 10.1478 10.1441 9.9915 9.8104 10.0403 9.9452 9.9728 9.9700 9.8093 9.6308 9.8515 9.7697 9.7777 9.7759 9.6285
Tempm = cell2mat(Temp)
Tempm = 26×6
10.0000 9.9000 9.9000 9.9100 9.9000 9.9000 10.7800 10.9000 10.7100 10.9000 10.7200 10.9000 11.7900 11.8900 11.7300 11.9000 11.7400 11.8900 12.8500 12.8900 12.8100 12.9000 12.8200 12.8900 13.9100 13.8800 13.9000 13.8900 13.8900 13.8900 14.9700 14.8800 14.9600 14.8900 14.9500 14.8900 16.0100 15.8800 16.0100 15.9000 16.0000 15.8800 17.0400 16.8800 17.0500 16.9000 17.0300 16.8800 18.0600 17.9000 18.0700 17.9000 18.0600 17.8800 19.0800 18.8800 19.0900 18.9000 19.0800 18.8900
Viscm = cell2mat(Visc)
Viscm = 26×6
11.4410 11.6310 11.7520 11.6190 11.6610 11.4450 11.2750 11.4360 11.6340 11.3920 11.5010 11.2360 11.1220 11.2090 11.4300 11.2060 11.3180 11.0170 10.8870 11.0120 11.1860 11.0080 11.0820 10.8140 10.6500 10.8240 10.9250 10.8200 10.8590 10.6480 10.4390 10.5940 10.7240 10.5890 10.6330 10.4380 10.2420 10.3890 10.4930 10.3820 10.4260 10.2400 10.0610 10.2100 10.2670 10.2040 10.1910 10.0610 9.8573 10.0560 10.0880 10.0510 9.9885 9.8922 9.6824 9.8678 9.9033 9.8640 9.8270 9.7075
figure
plot(Tempm, Viscm)
grid
xlabel('Temperature (°C)')
ylabel('Viscosity (mPa\cdots)')
title('Viscosity vs. Temperature')
axis('padded')
ViscMean = mean(Visci, 2); % Mean Of Interpolated Viscosity Vectors
ViscSE = std(Visci, [], 2) / sqrt(size(Visci,2)); % Standared Error Of Interpolated Viscosity Vectors
figure
errorbar(xq, ViscMean, ViscSE)
grid
xlabel('Temperature (°C)')
ylabel('Viscosity (mPa\cdots)')
title('Mean Viscosity vs. Temperature With Errors')
axis('padded')
return
Oilviscositytest10cst = table2array(T1(:, [1:6 8:14 16:end-1]))
T1(25:28,:)
xq = linspace(10,35,25);
% 10 cSt oil
% run 1
figure(1)
% run 1 ramp up
temp_1_rup_10 = Oilviscositytest10cst(2:27,3);
viscosity_1_rup_10 = Oilviscositytest10cst(2:27,5);
vq_1_up_10 = interp1(temp_1_rup_10,viscosity_1_rup_10,xq);
plot(xq,vq_1_up_10,'r')
hold on
plot(temp_1_rup_10,viscosity_1_rup_10,'ko')
title('10 cSt oil')
% run 1 ramp down
temp_1_rdown_10 = Oilviscositytest10cst(35:60,3);
viscosity_1_rdown_10 = Oilviscositytest10cst(35:60,5);
vq_1_down_10 = interp1(temp_1_rdown_10,viscosity_1_rdown_10,xq);
plot(xq,vq_1_down_10,'b')
hold on
plot(temp_1_rdown_10,viscosity_1_rdown_10,'ko')
% run 2
% run 2 ramp up
temp_2_rup_10 = Oilviscositytest10cst(2:27,11);
viscosity_2_rup_10 = Oilviscositytest10cst(2:27,13);
vq_2_up_10 = interp1(temp_2_rup_10,viscosity_2_rup_10,xq);
plot(xq,vq_2_up_10,'c')
hold on
plot(temp_2_rup_10,viscosity_2_rup_10,'ko')
% run 2 ramp down
temp_2_rdown_10 = Oilviscositytest10cst(35:60,11);
viscosity_2_rdown_10 = Oilviscositytest10cst(35:60,13);
vq_2_down_10 = interp1(temp_2_rdown_10,viscosity_2_rdown_10,xq);
plot(xq,vq_2_down_10,'g')
hold on
plot(temp_2_rdown_10,viscosity_2_rdown_10,'ko')
% run 3
% run 3 ramp up
temp_3_rup_10 = Oilviscositytest10cst(2:27,3);
viscosity_3_rup_10 = Oilviscositytest10cst(2:27,5);
vq_3_up_10 = interp1(temp_3_rup_10,viscosity_3_rup_10,xq);
plot(xq,vq_3_up_10,'r')
hold on
plot(temp_3_rup_10,viscosity_3_rup_10,'ko')
% run 3 ramp down
temp_3_rdown_10 = Oilviscositytest10cst(35:60,3);
viscosity_3_rdown_10 = Oilviscositytest10cst(35:60,5);
vq_3_down_10 = interp1(temp_3_rdown_10,viscosity_3_rdown_10,xq);
plot(xq,vq_3_down_10,'b')
hold on
plot(temp_3_rdown_10,viscosity_3_rdown_10,'ko')
% average viscosity
six = 6*(ones(1,1));
addition_vq_10 = vq_1_up_10 + vq_1_down_10 + vq_2_up_10 + vq_2_down_10 + vq_3_up_10 + vq_3_down_10;
average_vq_10 = addition_vq_10/six;
plot(xq,average_vq_10,'k')
plot(xq, average_vq_10, 'ko')
err_10 = (std(average_vq_10,[],2)/sqrt(size(average_vq_10,2)))
e_10 = errorbar(xq,average_vq_10,err_10);
figure(2)
plot(xq,average_vq_10,'m')
hold on
plot(xq, average_vq_10, 'ko')
This is not easy data to works with, however I believe this does essentially what you requested.
EDIT — (17 Dec 2023 at 13:25)
I found an error in my earlier code. This version works correctly.
.
  2 个评论
Daniel Jackson
Daniel Jackson 2023-12-16
The issue is all of the data sets should be on the same graph, where an average interpolation is then found. Where the standard deviation is calculated for the 6 data points (3 from the up-ramp and 3 from the down-ramp) for each temperature (after interpolation). The standard deviation should be different for each temperature point. In which the standard deviation error bars are plotted onto the averaged data.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Contour Plots 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by