How to simplify this script

2 views (last 30 days)
Navaneeth
Navaneeth on 12 Mar 2024
Commented: Navaneeth on 12 Mar 2024
I have written a program that calculate certain variations, but I feel like this can be much optimized but dont know how. I also want to calculate percentage change alsways in positive but getting negetive values for now.
clc;
clear;
close all;
format short
half_angle = 0.577:0.001:0.768;
theta = 2.*half_angle;
t = 0.4e-3; %thickness
n = 1.523;
HBC = zeros(size(half_angle));
Stopper_height_1 = zeros(size(half_angle));
Stopper_height_2 = zeros(size(half_angle));
Stopper_position_1 = zeros(size(half_angle));
Stopper_position_2 = zeros(size(half_angle));
Stopper_width = zeros(size(half_angle));
delta_y_raw = zeros(size(half_angle));
delta_y_raw_um = zeros(size(half_angle));
for i = 1: length(half_angle)
%relation between half angle and HBC
p1 = 0.0039 ;
p2 = 0.0363 ;
p3 = 1.1748 ;
HBC(i) = p1*half_angle(i)^2 + p2*half_angle(i) + p3;
%relation between half angle and Stopper_height
p1 = -0.0039 ;
p2 = -0.0363 ;
p3 = 0.7722 ;
Stopper_height_1(i) = p1*half_angle(i)^2 + p2*half_angle(i) + p3;
%relation between half angle and Stopper_height
p1 = -0.0039 ;
p2 = -0.0363 ;
p3 = 0.7782 ;
Stopper_height_2(i) = p1*half_angle(i)^2 + p2*half_angle(i) + p3;
%relation between half angle and Stopper position
p1 = -0.0131 ;
p2 = -0.1209 ;
p3 = 2.9141 ;
Stopper_position_1(i) = p1*half_angle(i)^2 + p2*half_angle(i) + p3;
%relation between half angle and Stopper position
p1 = -0.0131 ;
p2 = -0.1209 ;
p3 = 1.0841 ;
Stopper_position_2(i) = p1*half_angle(i)^2 + p2*half_angle(i) + p3;
%relation between half angle and Stopper width
p1 = -0.0066 ;
p2 = -0.0604 ;
p3 = 0.4421 ;
Stopper_width(i) = p1*half_angle(i)^2 + p2*half_angle(i) + p3;
delta_y_raw(i) = t*sind(theta(i))*(1 - sqrt((1-sind(theta(i))^2)/(n^2 - sind(theta(i))^2)));
delta_y_ori = 3.045252772520746e-6;
delta_y_raw_um(i) = delta_y_raw(i)/1e-6;
percentage = ((delta_y_ori-delta_y_raw)/delta_y_ori)*100;
if percentage(i) <0
percentage(i) = -1*percentage(i);
end
end
half_angle = half_angle';
theta = theta';
HBC = HBC';
Stopper_width = Stopper_width';
Stopper_height_1 = Stopper_height_1';
Stopper_height_2 = Stopper_height_2';
Stopper_position_1 = Stopper_position_1';
Stopper_position_2 = Stopper_position_2';
delta_y_raw_um = delta_y_raw_um';
percentage = percentage';
T = table(theta,half_angle,HBC,Stopper_height_1,Stopper_height_2,Stopper_position_1 ,Stopper_position_2,Stopper_width,delta_y_raw_um,percentage);
n_decimal = 3;
% create a new table
new_T = varfun(@(x) num2str(x, ['%' sprintf('.%df', n_decimal)]), T);
% preserve the variable names and the row names in the original table
new_T.Properties.VariableNames = T.Properties.VariableNames;
new_T.Properties.RowNames = T.Properties.RowNames;
writetable(new_T,'Variation_tolerance_with_angle.csv','Delimiter',',','QuoteStrings','all')
type 'Variation_tolerance_with_angle.csv'
theta,half_angle,HBC,Stopper_height_1,Stopper_height_2,Stopper_position_1,Stopper_position_2,Stopper_width,delta_y_raw_um,percentage "1.154","0.577","1.197","0.750","0.756","2.840","1.010","0.405","2.767"," 9.137" "1.156","0.578","1.197","0.750","0.756","2.840","1.010","0.405","2.772"," 8.979" "1.158","0.579","1.197","0.750","0.756","2.840","1.010","0.405","2.777"," 8.822" "1.160","0.580","1.197","0.750","0.756","2.840","1.010","0.405","2.781"," 8.664" "1.162","0.581","1.197","0.750","0.756","2.839","1.009","0.405","2.786"," 8.507" "1.164","0.582","1.197","0.750","0.756","2.839","1.009","0.405","2.791"," 8.349" "1.166","0.583","1.197","0.750","0.756","2.839","1.009","0.405","2.796"," 8.192" "1.168","0.584","1.197","0.750","0.756","2.839","1.009","0.405","2.801"," 8.034" "1.170","0.585","1.197","0.750","0.756","2.839","1.009","0.405","2.805"," 7.877" "1.172","0.586","1.197","0.750","0.756","2.839","1.009","0.404","2.810"," 7.719" "1.174","0.587","1.197","0.750","0.756","2.839","1.009","0.404","2.815"," 7.562" "1.176","0.588","1.197","0.750","0.756","2.838","1.008","0.404","2.820"," 7.404" "1.178","0.589","1.198","0.749","0.755","2.838","1.008","0.404","2.825"," 7.246" "1.180","0.590","1.198","0.749","0.755","2.838","1.008","0.404","2.829"," 7.089" "1.182","0.591","1.198","0.749","0.755","2.838","1.008","0.404","2.834"," 6.931" "1.184","0.592","1.198","0.749","0.755","2.838","1.008","0.404","2.839"," 6.774" "1.186","0.593","1.198","0.749","0.755","2.838","1.008","0.404","2.844"," 6.616" "1.188","0.594","1.198","0.749","0.755","2.838","1.008","0.404","2.849"," 6.459" "1.190","0.595","1.198","0.749","0.755","2.838","1.008","0.404","2.853"," 6.301" "1.192","0.596","1.198","0.749","0.755","2.837","1.007","0.404","2.858"," 6.144" "1.194","0.597","1.198","0.749","0.755","2.837","1.007","0.404","2.863"," 5.986" "1.196","0.598","1.198","0.749","0.755","2.837","1.007","0.404","2.868"," 5.829" "1.198","0.599","1.198","0.749","0.755","2.837","1.007","0.404","2.873"," 5.671" "1.200","0.600","1.198","0.749","0.755","2.837","1.007","0.403","2.877"," 5.514" "1.202","0.601","1.198","0.749","0.755","2.837","1.007","0.403","2.882"," 5.356" "1.204","0.602","1.198","0.749","0.755","2.837","1.007","0.403","2.887"," 5.199" "1.206","0.603","1.198","0.749","0.755","2.836","1.006","0.403","2.892"," 5.041" "1.208","0.604","1.198","0.749","0.755","2.836","1.006","0.403","2.897"," 4.884" "1.210","0.605","1.198","0.749","0.755","2.836","1.006","0.403","2.901"," 4.726" "1.212","0.606","1.198","0.749","0.755","2.836","1.006","0.403","2.906"," 4.569" "1.214","0.607","1.198","0.749","0.755","2.836","1.006","0.403","2.911"," 4.411" "1.216","0.608","1.198","0.749","0.755","2.836","1.006","0.403","2.916"," 4.253" "1.218","0.609","1.198","0.749","0.755","2.836","1.006","0.403","2.921"," 4.096" "1.220","0.610","1.198","0.749","0.755","2.835","1.005","0.403","2.925"," 3.938" "1.222","0.611","1.198","0.749","0.755","2.835","1.005","0.403","2.930"," 3.781" "1.224","0.612","1.198","0.749","0.755","2.835","1.005","0.403","2.935"," 3.623" "1.226","0.613","1.199","0.748","0.754","2.835","1.005","0.403","2.940"," 3.466" "1.228","0.614","1.199","0.748","0.754","2.835","1.005","0.403","2.945"," 3.308" "1.230","0.615","1.199","0.748","0.754","2.835","1.005","0.402","2.949"," 3.151" "1.232","0.616","1.199","0.748","0.754","2.835","1.005","0.402","2.954"," 2.993" "1.234","0.617","1.199","0.748","0.754","2.835","1.005","0.402","2.959"," 2.836" "1.236","0.618","1.199","0.748","0.754","2.834","1.004","0.402","2.964"," 2.678" "1.238","0.619","1.199","0.748","0.754","2.834","1.004","0.402","2.968"," 2.521" "1.240","0.620","1.199","0.748","0.754","2.834","1.004","0.402","2.973"," 2.363" "1.242","0.621","1.199","0.748","0.754","2.834","1.004","0.402","2.978"," 2.206" "1.244","0.622","1.199","0.748","0.754","2.834","1.004","0.402","2.983"," 2.048" "1.246","0.623","1.199","0.748","0.754","2.834","1.004","0.402","2.988"," 1.890" "1.248","0.624","1.199","0.748","0.754","2.834","1.004","0.402","2.992"," 1.733" "1.250","0.625","1.199","0.748","0.754","2.833","1.003","0.402","2.997"," 1.575" "1.252","0.626","1.199","0.748","0.754","2.833","1.003","0.402","3.002"," 1.418" "1.254","0.627","1.199","0.748","0.754","2.833","1.003","0.402","3.007"," 1.260" "1.256","0.628","1.199","0.748","0.754","2.833","1.003","0.402","3.012"," 1.103" "1.258","0.629","1.199","0.748","0.754","2.833","1.003","0.401","3.016"," 0.945" "1.260","0.630","1.199","0.748","0.754","2.833","1.003","0.401","3.021"," 0.788" "1.262","0.631","1.199","0.748","0.754","2.833","1.003","0.401","3.026"," 0.630" "1.264","0.632","1.199","0.748","0.754","2.832","1.002","0.401","3.031"," 0.473" "1.266","0.633","1.199","0.748","0.754","2.832","1.002","0.401","3.036"," 0.315" "1.268","0.634","1.199","0.748","0.754","2.832","1.002","0.401","3.040"," 0.158" "1.270","0.635","1.199","0.748","0.754","2.832","1.002","0.401","3.045"," 0.000" "1.272","0.636","1.199","0.748","0.754","2.832","1.002","0.401","3.050"," -0.158" "1.274","0.637","1.200","0.747","0.753","2.832","1.002","0.401","3.055"," -0.315" "1.276","0.638","1.200","0.747","0.753","2.832","1.002","0.401","3.060"," -0.473" "1.278","0.639","1.200","0.747","0.753","2.831","1.001","0.401","3.064"," -0.630" "1.280","0.640","1.200","0.747","0.753","2.831","1.001","0.401","3.069"," -0.788" "1.282","0.641","1.200","0.747","0.753","2.831","1.001","0.401","3.074"," -0.945" "1.284","0.642","1.200","0.747","0.753","2.831","1.001","0.401","3.079"," -1.103" "1.286","0.643","1.200","0.747","0.753","2.831","1.001","0.401","3.084"," -1.260" "1.288","0.644","1.200","0.747","0.753","2.831","1.001","0.400","3.088"," -1.418" "1.290","0.645","1.200","0.747","0.753","2.831","1.001","0.400","3.093"," -1.575" "1.292","0.646","1.200","0.747","0.753","2.831","1.001","0.400","3.098"," -1.733" "1.294","0.647","1.200","0.747","0.753","2.830","1.000","0.400","3.103"," -1.890" "1.296","0.648","1.200","0.747","0.753","2.830","1.000","0.400","3.108"," -2.048" "1.298","0.649","1.200","0.747","0.753","2.830","1.000","0.400","3.112"," -2.206" "1.300","0.650","1.200","0.747","0.753","2.830","1.000","0.400","3.117"," -2.363" "1.302","0.651","1.200","0.747","0.753","2.830","1.000","0.400","3.122"," -2.521" "1.304","0.652","1.200","0.747","0.753","2.830","1.000","0.400","3.127"," -2.678" "1.306","0.653","1.200","0.747","0.753","2.830","1.000","0.400","3.132"," -2.836" "1.308","0.654","1.200","0.747","0.753","2.829","0.999","0.400","3.136"," -2.993" "1.310","0.655","1.200","0.747","0.753","2.829","0.999","0.400","3.141"," -3.151" "1.312","0.656","1.200","0.747","0.753","2.829","0.999","0.400","3.146"," -3.308" "1.314","0.657","1.200","0.747","0.753","2.829","0.999","0.400","3.151"," -3.466" "1.316","0.658","1.200","0.747","0.753","2.829","0.999","0.399","3.156"," -3.623" "1.318","0.659","1.200","0.747","0.753","2.829","0.999","0.399","3.160"," -3.781" "1.320","0.660","1.200","0.747","0.753","2.829","0.999","0.399","3.165"," -3.939" "1.322","0.661","1.200","0.747","0.753","2.828","0.998","0.399","3.170"," -4.096" "1.324","0.662","1.201","0.746","0.752","2.828","0.998","0.399","3.175"," -4.254" "1.326","0.663","1.201","0.746","0.752","2.828","0.998","0.399","3.180"," -4.411" "1.328","0.664","1.201","0.746","0.752","2.828","0.998","0.399","3.184"," -4.569" "1.330","0.665","1.201","0.746","0.752","2.828","0.998","0.399","3.189"," -4.726" "1.332","0.666","1.201","0.746","0.752","2.828","0.998","0.399","3.194"," -4.884" "1.334","0.667","1.201","0.746","0.752","2.828","0.998","0.399","3.199"," -5.041" "1.336","0.668","1.201","0.746","0.752","2.827","0.997","0.399","3.204"," -5.199" "1.338","0.669","1.201","0.746","0.752","2.827","0.997","0.399","3.208"," -5.356" "1.340","0.670","1.201","0.746","0.752","2.827","0.997","0.399","3.213"," -5.514" "1.342","0.671","1.201","0.746","0.752","2.827","0.997","0.399","3.218"," -5.672" "1.344","0.672","1.201","0.746","0.752","2.827","0.997","0.399","3.223"," -5.829" "1.346","0.673","1.201","0.746","0.752","2.827","0.997","0.398","3.228"," -5.987" "1.348","0.674","1.201","0.746","0.752","2.827","0.997","0.398","3.232"," -6.144" "1.350","0.675","1.201","0.746","0.752","2.827","0.997","0.398","3.237"," -6.302" "1.352","0.676","1.201","0.746","0.752","2.826","0.996","0.398","3.242"," -6.459" "1.354","0.677","1.201","0.746","0.752","2.826","0.996","0.398","3.247"," -6.617" "1.356","0.678","1.201","0.746","0.752","2.826","0.996","0.398","3.252"," -6.774" "1.358","0.679","1.201","0.746","0.752","2.826","0.996","0.398","3.256"," -6.932" "1.360","0.680","1.201","0.746","0.752","2.826","0.996","0.398","3.261"," -7.090" "1.362","0.681","1.201","0.746","0.752","2.826","0.996","0.398","3.266"," -7.247" "1.364","0.682","1.201","0.746","0.752","2.826","0.996","0.398","3.271"," -7.405" "1.366","0.683","1.201","0.746","0.752","2.825","0.995","0.398","3.276"," -7.562" "1.368","0.684","1.201","0.746","0.752","2.825","0.995","0.398","3.280"," -7.720" "1.370","0.685","1.201","0.746","0.752","2.825","0.995","0.398","3.285"," -7.877" "1.372","0.686","1.202","0.745","0.751","2.825","0.995","0.398","3.290"," -8.035" "1.374","0.687","1.202","0.745","0.751","2.825","0.995","0.397","3.295"," -8.192" "1.376","0.688","1.202","0.745","0.751","2.825","0.995","0.397","3.300"," -8.350" "1.378","0.689","1.202","0.745","0.751","2.825","0.995","0.397","3.304"," -8.508" "1.380","0.690","1.202","0.745","0.751","2.824","0.994","0.397","3.309"," -8.665" "1.382","0.691","1.202","0.745","0.751","2.824","0.994","0.397","3.314"," -8.823" "1.384","0.692","1.202","0.745","0.751","2.824","0.994","0.397","3.319"," -8.980" "1.386","0.693","1.202","0.745","0.751","2.824","0.994","0.397","3.324"," -9.138" "1.388","0.694","1.202","0.745","0.751","2.824","0.994","0.397","3.328"," -9.295" "1.390","0.695","1.202","0.745","0.751","2.824","0.994","0.397","3.333"," -9.453" "1.392","0.696","1.202","0.745","0.751","2.824","0.994","0.397","3.338"," -9.610" "1.394","0.697","1.202","0.745","0.751","2.823","0.993","0.397","3.343"," -9.768" "1.396","0.698","1.202","0.745","0.751","2.823","0.993","0.397","3.348"," -9.926" "1.398","0.699","1.202","0.745","0.751","2.823","0.993","0.397","3.352","-10.083" "1.400","0.700","1.202","0.745","0.751","2.823","0.993","0.397","3.357","-10.241" "1.402","0.701","1.202","0.745","0.751","2.823","0.993","0.397","3.362","-10.398" "1.404","0.702","1.202","0.745","0.751","2.823","0.993","0.396","3.367","-10.556" "1.406","0.703","1.202","0.745","0.751","2.823","0.993","0.396","3.371","-10.713" "1.408","0.704","1.202","0.745","0.751","2.822","0.992","0.396","3.376","-10.871" "1.410","0.705","1.202","0.745","0.751","2.822","0.992","0.396","3.381","-11.028" "1.412","0.706","1.202","0.745","0.751","2.822","0.992","0.396","3.386","-11.186" "1.414","0.707","1.202","0.745","0.751","2.822","0.992","0.396","3.391","-11.344" "1.416","0.708","1.202","0.745","0.751","2.822","0.992","0.396","3.395","-11.501" "1.418","0.709","1.202","0.745","0.751","2.822","0.992","0.396","3.400","-11.659" "1.420","0.710","1.203","0.744","0.750","2.822","0.992","0.396","3.405","-11.816" "1.422","0.711","1.203","0.744","0.750","2.822","0.992","0.396","3.410","-11.974" "1.424","0.712","1.203","0.744","0.750","2.821","0.991","0.396","3.415","-12.131" "1.426","0.713","1.203","0.744","0.750","2.821","0.991","0.396","3.419","-12.289" "1.428","0.714","1.203","0.744","0.750","2.821","0.991","0.396","3.424","-12.446" "1.430","0.715","1.203","0.744","0.750","2.821","0.991","0.396","3.429","-12.604" "1.432","0.716","1.203","0.744","0.750","2.821","0.991","0.395","3.434","-12.762" "1.434","0.717","1.203","0.744","0.750","2.821","0.991","0.395","3.439","-12.919" "1.436","0.718","1.203","0.744","0.750","2.821","0.991","0.395","3.443","-13.077" "1.438","0.719","1.203","0.744","0.750","2.820","0.990","0.395","3.448","-13.234" "1.440","0.720","1.203","0.744","0.750","2.820","0.990","0.395","3.453","-13.392" "1.442","0.721","1.203","0.744","0.750","2.820","0.990","0.395","3.458","-13.549" "1.444","0.722","1.203","0.744","0.750","2.820","0.990","0.395","3.463","-13.707" "1.446","0.723","1.203","0.744","0.750","2.820","0.990","0.395","3.467","-13.865" "1.448","0.724","1.203","0.744","0.750","2.820","0.990","0.395","3.472","-14.022" "1.450","0.725","1.203","0.744","0.750","2.820","0.990","0.395","3.477","-14.180" "1.452","0.726","1.203","0.744","0.750","2.819","0.989","0.395","3.482","-14.337" "1.454","0.727","1.203","0.744","0.750","2.819","0.989","0.395","3.487","-14.495" "1.456","0.728","1.203","0.744","0.750","2.819","0.989","0.395","3.491","-14.652" "1.458","0.729","1.203","0.744","0.750","2.819","0.989","0.395","3.496","-14.810" "1.460","0.730","1.203","0.744","0.750","2.819","0.989","0.394","3.501","-14.967" "1.462","0.731","1.203","0.744","0.750","2.819","0.989","0.394","3.506","-15.125" "1.464","0.732","1.203","0.744","0.750","2.819","0.989","0.394","3.511","-15.283" "1.466","0.733","1.204","0.743","0.749","2.818","0.988","0.394","3.515","-15.440" "1.468","0.734","1.204","0.743","0.749","2.818","0.988","0.394","3.520","-15.598" "1.470","0.735","1.204","0.743","0.749","2.818","0.988","0.394","3.525","-15.755" "1.472","0.736","1.204","0.743","0.749","2.818","0.988","0.394","3.530","-15.913" "1.474","0.737","1.204","0.743","0.749","2.818","0.988","0.394","3.535","-16.070" "1.476","0.738","1.204","0.743","0.749","2.818","0.988","0.394","3.539","-16.228" "1.478","0.739","1.204","0.743","0.749","2.818","0.988","0.394","3.544","-16.386" "1.480","0.740","1.204","0.743","0.749","2.817","0.987","0.394","3.549","-16.543" "1.482","0.741","1.204","0.743","0.749","2.817","0.987","0.394","3.554","-16.701" "1.484","0.742","1.204","0.743","0.749","2.817","0.987","0.394","3.559","-16.858" "1.486","0.743","1.204","0.743","0.749","2.817","0.987","0.394","3.563","-17.016" "1.488","0.744","1.204","0.743","0.749","2.817","0.987","0.394","3.568","-17.173" "1.490","0.745","1.204","0.743","0.749","2.817","0.987","0.393","3.573","-17.331" "1.492","0.746","1.204","0.743","0.749","2.817","0.987","0.393","3.578","-17.489" "1.494","0.747","1.204","0.743","0.749","2.816","0.986","0.393","3.583","-17.646" "1.496","0.748","1.204","0.743","0.749","2.816","0.986","0.393","3.587","-17.804" "1.498","0.749","1.204","0.743","0.749","2.816","0.986","0.393","3.592","-17.961" "1.500","0.750","1.204","0.743","0.749","2.816","0.986","0.393","3.597","-18.119" "1.502","0.751","1.204","0.743","0.749","2.816","0.986","0.393","3.602","-18.276" "1.504","0.752","1.204","0.743","0.749","2.816","0.986","0.393","3.607","-18.434" "1.506","0.753","1.204","0.743","0.749","2.816","0.986","0.393","3.611","-18.592" "1.508","0.754","1.204","0.743","0.749","2.815","0.985","0.393","3.616","-18.749" "1.510","0.755","1.204","0.743","0.749","2.815","0.985","0.393","3.621","-18.907" "1.512","0.756","1.204","0.743","0.749","2.815","0.985","0.393","3.626","-19.064" "1.514","0.757","1.205","0.742","0.748","2.815","0.985","0.393","3.631","-19.222" "1.516","0.758","1.205","0.742","0.748","2.815","0.985","0.393","3.635","-19.379" "1.518","0.759","1.205","0.742","0.748","2.815","0.985","0.392","3.640","-19.537" "1.520","0.760","1.205","0.742","0.748","2.815","0.985","0.392","3.645","-19.695" "1.522","0.761","1.205","0.742","0.748","2.815","0.985","0.392","3.650","-19.852" "1.524","0.762","1.205","0.742","0.748","2.814","0.984","0.392","3.655","-20.010" "1.526","0.763","1.205","0.742","0.748","2.814","0.984","0.392","3.659","-20.167" "1.528","0.764","1.205","0.742","0.748","2.814","0.984","0.392","3.664","-20.325" "1.530","0.765","1.205","0.742","0.748","2.814","0.984","0.392","3.669","-20.483" "1.532","0.766","1.205","0.742","0.748","2.814","0.984","0.392","3.674","-20.640" "1.534","0.767","1.205","0.742","0.748","2.814","0.984","0.392","3.679","-20.798" "1.536","0.768","1.205","0.742","0.748","2.814","0.984","0.392","3.683"," 20.955"
Any kind of help is much appreciated,thank you for your time.
Regards,

Accepted Answer

VBBV
VBBV on 12 Mar 2024
Use abs percentage for error calculation
percentage = abs((delta_y_ori-delta_y_raw)/delta_y_ori)*100;
  2 Comments
VBBV
VBBV on 12 Mar 2024
clc;
clear;
close all;
format short
half_angle = 0.577:0.001:0.768;
theta = 2.*half_angle;
t = 0.4e-3; %thickness
n = 1.523;
HBC = zeros(size(half_angle));
Stopper_height_1 = zeros(size(half_angle));
Stopper_height_2 = zeros(size(half_angle));
Stopper_position_1 = zeros(size(half_angle));
Stopper_position_2 = zeros(size(half_angle));
Stopper_width = zeros(size(half_angle));
delta_y_raw = zeros(size(half_angle));
delta_y_raw_um = zeros(size(half_angle));
%relation between half angle and HBC
p11 = 0.0039 ;
p21 = 0.0363 ;
p31 = 1.1748 ;
%relation between half angle and Stopper width
p16 = -0.0066 ;
p26 = -0.0604 ;
p36 = 0.4421 ;
%relation between half angle and Stopper_height
p12 = -0.0039 ;
p22 = -0.0363 ;
p32 = 0.7722 ;
%relation between half angle and Stopper_height
p13 = -0.0039 ;
p23 = -0.0363 ;
p33 = 0.7782 ;
%relation between half angle and Stopper position
p14 = -0.0131 ;
p24 = -0.1209 ;
p34 = 2.9141 ;
%relation between half angle and Stopper position
p15 = -0.0131 ;
p25 = -0.1209 ;
p35 = 1.0841 ;
HBC = p11*half_angle.^2 + p21*half_angle + p31;
Stopper_height_1 = p12*half_angle.^2 + p22*half_angle + p32;
Stopper_height_2 = p13*half_angle.^2 + p23*half_angle + p33;
Stopper_position_1 = p14*half_angle.^2 + p24*half_angle + p34;
Stopper_position_2 = p15*half_angle.^2 + p25*half_angle + p35;
Stopper_width = p16*half_angle.^2 + p26*half_angle + p36;
delta_y_raw = t*sind(theta).*(1 - sqrt((1-sind(theta).^2)./(n^2 - sind(theta).^2)));
delta_y_ori = 3.045252772520746e-6;
delta_y_raw_um = delta_y_raw/1e-6;
percentage = abs((delta_y_ori-delta_y_raw)./delta_y_ori)*100;
if percentage <0
percentage = -1*percentage;
end
T = table(theta.',half_angle.',HBC.',Stopper_height_1.',Stopper_height_2.',Stopper_position_1.' ,Stopper_position_2.',Stopper_width.',delta_y_raw_um.',percentage.');
n_decimal = 3;
% create a new table
new_T = varfun(@(x) num2str(x, ['%' sprintf('.%df', n_decimal)]), T)
new_T = 192×10 table
Fun_Var1 Fun_Var2 Fun_Var3 Fun_Var4 Fun_Var5 Fun_Var6 Fun_Var7 Fun_Var8 Fun_Var9 Fun_Var10 ________ ________ ________ ________ ________ ________ ________ ________ ________ _________ 1.154 0.577 1.197 0.750 0.756 2.840 1.010 0.405 2.767 9.137 1.156 0.578 1.197 0.750 0.756 2.840 1.010 0.405 2.772 8.979 1.158 0.579 1.197 0.750 0.756 2.840 1.010 0.405 2.777 8.822 1.160 0.580 1.197 0.750 0.756 2.840 1.010 0.405 2.781 8.664 1.162 0.581 1.197 0.750 0.756 2.839 1.009 0.405 2.786 8.507 1.164 0.582 1.197 0.750 0.756 2.839 1.009 0.405 2.791 8.349 1.166 0.583 1.197 0.750 0.756 2.839 1.009 0.405 2.796 8.192 1.168 0.584 1.197 0.750 0.756 2.839 1.009 0.405 2.801 8.034 1.170 0.585 1.197 0.750 0.756 2.839 1.009 0.405 2.805 7.877 1.172 0.586 1.197 0.750 0.756 2.839 1.009 0.404 2.810 7.719 1.174 0.587 1.197 0.750 0.756 2.839 1.009 0.404 2.815 7.562 1.176 0.588 1.197 0.750 0.756 2.838 1.008 0.404 2.820 7.404 1.178 0.589 1.198 0.749 0.755 2.838 1.008 0.404 2.825 7.246 1.180 0.590 1.198 0.749 0.755 2.838 1.008 0.404 2.829 7.089 1.182 0.591 1.198 0.749 0.755 2.838 1.008 0.404 2.834 6.931 1.184 0.592 1.198 0.749 0.755 2.838 1.008 0.404 2.839 6.774
% % preserve the variable names and the row names in the original table
% new_T.Properties.VariableNames = T.Properties.VariableNames;
% new_T.Properties.RowNames = T.Properties.RowNames;
%
% writetable(new_T,'Variation_tolerance_with_angle.csv','Delimiter',',','QuoteStrings','all')
% type 'Variation_tolerance_with_angle.csv'
Navaneeth
Navaneeth on 12 Mar 2024
Thank you for this.

Sign in to comment.

More Answers (0)

Categories

Find more on Tables in Help Center and File Exchange

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!