Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %M=[44.71756,2554.679,2265.398,2576.034,2867.556,2667.752,2632.009,2600.986,2599.868;
- % 44.14105,4206.833,4681.949,5677.823,6185.949,5101.299,6596.67,6414.134,1;
- % 43.75766,4298.244,5801.197,2930.065,5323.585,2079.171,2078.888,2747.259,1;
- % 43.18222,81941.96,89244.75,78504.41,63392.84,63388.52,6319.933,4119.334,1;
- % 42.60572,12237.45,11236.08,12505.07,13619.54,13054.42,16876.52,12511.04,1;
- % 41.45342,149102.6,155620.9,101475.3,110534,192717.7,233582.2,228677,1;
- % 40.49352,21808.74,20459.26,17619.12,22288.7,348237.8,14841.43,12242.46,1];
- %S=[44.71756,44.14105,43.75766,43.18222,42.60572,41.45342,40.49352]; % stress array
- N=26; %number of stress
- arr=[2262,2320,2321,2365,2400,2450,2451,2452,2465,2500,2501,2511,2515,2555,2556,2566,2567,2568,2615,2616,2617,2666,2667,2715,2715,2765,2820];
- length(arr)
- for i=1:1 % for different stress
- %arr=M(i,:);
- arr=sort(arr);
- %int p=0;
- x=(arr(2)-10):(arr(N+1)+10);
- %int s1=int32(arr(2));
- %int s2=mod(s1,10);
- s=2260;
- %int e1=int32(arr(N+1));
- %int e2=mod(e1,10);
- e=2870;
- %p=(e-s)/10;
- p=0;
- s_temp=s;
- while s_temp<e
- p=p+1;
- s_temp=s_temp+50;
- end
- x_co=zeros(1,p);
- y_co=zeros(1,p);
- ct=1;
- w=0;
- while s<=e
- mn=s;
- mx=s+50;
- count=0;
- for j=1:27
- ele=arr(j);
- if ele>=mn && ele<=mx
- count=count+1;
- %else
- % break;
- end
- end
- x_co(ct)=(mn+mx)/2;
- y_co(ct)=count;
- if count>0
- w=w+1;
- end
- ct=ct+1;
- s=s+50;
- % if s>=e
- % break;
- %end
- end
- x_coo=zeros(1,w);
- y_coo=zeros(1,w);
- l=1;
- for k=1:p
- if y_co(k)>0
- y_coo(l)=y_co(k);
- x_coo(l)=x_co(k);
- l=l+1;
- end
- end
- %plot(x_coo,y_coo);
- % ... (previous code)
- % Fit a log-normal distribution to your data
- % Define the distribution object using the 'lognormal' distribution type
- % ... (previous code)
- % Fit a normal distribution to your data
- % Define the distribution object using the 'Normal' distribution type
- % ... (previous code)
- % Fit a normal distribution to your data
- % Define the distribution object using the 'Normal' distribution type
- % ... (previous code)
- % Fit a normal distribution to your data
- % Define the distribution object using the 'Normal' distribution type
- % ... (previous code)
- % Fit a normal distribution to your data
- % Define the distribution object using the 'Normal' distribution type
- % ... (previous code)
- % Fit a normal distribution to your data
- % Define the distribution object using the 'Normal' distribution type
- % ... (previous code)
- % Fit a normal distribution to your data
- % Define the distribution object using the 'Normal' distribution type
- % ... (previous code)
- % Create a bar plot to connect the data points
- pd = fitdist(x_coo', 'Normal'); % Note the transpose of x_coo
- % Extract the parameters of the fitted distribution
- mu = pd.mu;
- sigma = pd.sigma;
- % Generate x-values for the curve with smaller increments
- x_values = min(x_coo):10:max(x_coo); % Use smaller increments for a smoother curve
- % Calculate the corresponding y-values for the normal distribution using the fitted parameters
- y_fit = pdf(pd, x_values);
- % Create a bar plot to connect the data points
- bar(x_coo, y_coo, 'yellow', 'BarWidth', 1);
- hold on;
- % Overlay the fitted Normal (Gaussian) curve
- plot(x_values, y_fit, 'r-', 'LineWidth', 2);
- legend('Data Points', 'LogNormal');
- % ... (rest of your code)
- %%%%%%%%%%%%%%%%%%%%%%%%%%%% Filtering Data and Plotting Smooth Curve %%%%%%%%%%%%%%%%%%%%%%%%%%%%
- filterSize = 2;
- x_mov_fil = zeros(length(x_coo)-filterSize+2, 1);
- y_mov_fil = zeros(length(x_coo)-filterSize+2, 1);
- x_mov_fil(1) = x_coo(1);
- y_mov_fil(1) = y_coo(1);
- for ii=1:length(x_coo) - filterSize+1
- x_mov_fil(ii+1) = (x_coo(ii) + x_coo(ii+1))/2;
- y_mov_fil(ii+1) = (y_coo(ii) + y_coo(ii+1))/2;
- end
- % Plotting approx plot
- [xx,is] = sort(x_mov_fil(:));
- yy = y_mov_fil(is);
- xx = smoothdata(xx, "sgolay");
- yy = smoothdata(yy, "sgolay");
- yy = yy(:);
- dx = diff(xx);
- dy = diff(yy);
- y0 = yy(1:end-1);
- n = numel(xx)-1;
- coefs = [-2*dy./(dx.^3), 3*dy./(dx.^2), 0*dy, y0];
- pp = struct('form', 'pp',...
- 'breaks', xx(:)',...
- 'coefs', coefs,...
- 'pieces', n, ...
- 'order', 4,...
- 'dim', 1);
- % figure
- xi = linspace(min(x_mov_fil),max(x_mov_fil));
- yi = ppval(pp,xi);
- plot(xi,yi,'r');
- xlim([min(x),max(x)])
- grid on
- % Max curve value x and y point
- [~, maxIdx] = max(yi);
- maxiX = xi(maxIdx);
- maxiY = yi(maxIdx);
- disp("Maximum value y= "+ maxiY+ " at x="+ maxiX)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement