rawdir=pwd; files=dir(rawdir); for i=3:3002 I_all(:,:,i-2)=dicomread(strcat(rawdir,"\",files(i).name)); end for i=1:150 I(:,:,i)=I_all(:,:,(i-1)*20+11); end % figure,plot(t,squeeze(I(194,77,:))) mask=roipoly; for i=1:size(I,3) Im=I(:,:,i); SIm(1,i)=mean(Im(mask)); SIstd(1,i)=std(double(Im(mask)),'omitnan'); end P=polyfit(t,SIm,4); x=linspace(1,size(I,3),100000); % build x-axis ft=polyval(P,x); % Fm=polyval(P,t); figure,plot(t,SIm,"",x,ft,'--') %% Fit: 'Smoothed data'. [xData, yData] = prepareCurveData( t, SIm ); % Set up fittype and options. ft = fittype( 'smoothingspline' ); opts = fitoptions( 'Method', 'SmoothingSpline' ); opts.SmoothingParam = 0.975807545131203; % Fit model to data. [fitresult, gof] = fit( xData, yData, ft, opts ); % Plot fit with data. figure( 'Name', 'Smoothed data' ); h = plot( fitresult, xData, yData ); legend( h, 'SIm vs. t', 'Smoothed data', 'Location', 'NorthEast', 'Interpreter', 'none' ); % Label axes xlabel( 't', 'Interpreter', 'none' ); ylabel( 'SIm', 'Interpreter', 'none' ); %% e = errorbar(t,SIm,SIstd/10) e.Color=[0 0 0]; e.LineStyle='none'; e.Marker='.'; e.MarkerSize = 12; e.CapSize = 5; hold on plot(fitresult,'b')