How can I set max & min value but maintain the curve trend?
7 views (last 30 days)
Show older comments
Hello everyone,
I have a fitting curve as you can see in figure below.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/899615/image.png)
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
load('wavelength.mat');
filename = ('PDA36A_spectrum2_sam.xlsx');
data = xlsread(filename);
points = data(:,1);
signal = data(:,2);
mask1 = signal>8000;
maskedSignal = signal(mask1);
maskedWave = wavelength(mask1);
coefficients = polyfit(maskedWave, maskedSignal, 5);
% Get smoothed signal.
smoothedSignal = polyval(coefficients,maskedWave');
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!
Accepted Answer
More Answers (1)
Voss
on 19 Feb 2022
clear all
clc
clf
close all
load('wavelength.mat');
filename = ('PDA36A_spectrum2_sam.xlsx');
data = xlsread(filename);
points = data(:,1);
signal = data(:,2);
mask1 = signal>8000;
maskedSignal = signal(mask1);
maskedWave = wavelength(mask1);
coefficients = polyfit(maskedWave, maskedSignal, 5);
% Get smoothed signal.
smoothedSignal = polyval(coefficients,maskedWave');
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);
plot(maskedWave,smoothedSignal);
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!