Interpolating a set of values
Afficher commentaires plus anciens
Hi,
I have datasheet with known temperatures, resistances and I have another set of resistance values that needs to be converetd into temperatures using the datasheet. I want to linearly interperolate each resistance values so I get its corresponding temperatures.
I am new to matlab. Any help on this would be appreciated. I have also attached the code I have for now (Note: all values are stored in an excel file).
%%
Datasheet=xlsread('name_of_sheet.xlsx','Sheet2');
known_Resistance=Datasheet(:,2);
known_Temp=Datasheet(:,1);
Meaured_Resistance=Datasheet(:,3);
Time=Datasheet(:,4);
Temp=interp1(known_Resistance,known_Temp,Meaured_Resistance);
plot(time,Temp)
%%
Thank you.
Réponses (1)
The problem is that xlsread returns a matrix with some NaNs since the data columns in the xlsx file do not all have the same amount of data:
unzip('name_of_sheet.xlsx.zip')
Datasheet=xlsread('name_of_sheet.xlsx','Sheet2');
disp(Datasheet(95:110,:));
One solution is to remove those NaNs from your variables before doing the interpolation:
known_Resistance=Datasheet(:,2);
known_Temp=Datasheet(:,1);
Meaured_Resistance=Datasheet(:,3);
Time=Datasheet(:,4);
% remove NaNs:
known_Resistance = known_Resistance(~isnan(known_Resistance));
known_Temp = known_Temp(~isnan(known_Temp));
Meaured_Resistance = Meaured_Resistance(~isnan(Meaured_Resistance)); % these two don't have NaNs
Time = Time(~isnan(Time)); % but what the hell
Temp=interp1(known_Resistance,known_Temp,Meaured_Resistance);
% plot(time,Temp)
plot(Time,Temp)
Catégories
En savoir plus sur Interpolation of 2-D Selections in 3-D Grids dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
