# How can I set max & min value but maintain the curve trend?

12 views (last 30 days)
Vivian Yu on 19 Feb 2022
Answered: Catalytic on 19 Feb 2022
Hello everyone,
I have a fitting curve as you can see in figure below. I want to make maximum value is equal to 1 and minimum value is equal to 0.
However, I also want to maintain the curve trend.
How can I do?
clear all
clc
clf
close all
filename = ('PDA36A_spectrum2_sam.xlsx');
points = data(:,1);
signal = data(:,2);
% Get smoothed signal.
figure
plot(maskedWave,smoothedSignal, 'r-', 'LineWidth', 2);
title('Weighting shape');
xlabel('wavelength (nm)');
ylabel('Ratio');
set(gca,'fontsize',15,'linewidth',1);
grid on
When I use function "interp1", the result is so bad.
smoothedSignal = smoothedSignal'./max(smoothedSignal);
range = linspace(0,1,length(smoothedSignal))';
spectruma=interp1(smoothedSignal,maskedWave,range,'spline'); %interpolate the exp data interp1(x,y,xi,method)
figure
plot(spectruma);
Thank you!
##### 1 CommentShowHide None
Walter Roberson on 19 Feb 2022
rescale()?

Catalytic on 19 Feb 2022
yourSignal = rescale(yourSignal)

### More Answers (1)

Voss on 19 Feb 2022
clear all
clc
clf
close all
filename = ('PDA36A_spectrum2_sam.xlsx');
points = data(:,1);
signal = data(:,2);
Warning: Polynomial is badly conditioned. Add points with distinct X values, reduce the degree of the polynomial, or try centering and scaling as described in HELP POLYFIT.
% Get smoothed signal.
figure
plot(maskedWave,smoothedSignal, 'r-', 'LineWidth', 2);
title('Weighting shape');
xlabel('wavelength (nm)');
ylabel('Ratio');
set(gca,'fontsize',15,'linewidth',1);
grid on % smoothedSignal = smoothedSignal'./max(smoothedSignal);
smoothedSignal = (smoothedSignal'-min(smoothedSignal))./(max(smoothedSignal)-min(smoothedSignal));
% smoothedSignal = rescale(smoothedSignal); % an alternative
% range = linspace(0,1,length(smoothedSignal))';
% spectruma=interp1(smoothedSignal,maskedWave,range,'spline'); %interpolate the exp data interp1(x,y,xi,method)
figure
% plot(spectruma); 