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.

5 Kommentare

Torsten
Torsten am 18 Apr. 2022
Bearbeitet: Torsten am 18 Apr. 2022
And what' your problem ? Does your code not work ?
AA
AA am 18 Apr. 2022
Yes, the code doesn't work. Below is the error I am getting.
%%Error using griddedInterpolant
The sample points must be finite.
Error in interp1 (line 136)
F = griddedInterpolant(X,V(:,1),method);
%%
Voss
Voss am 18 Apr. 2022
@AA Perhaps you can upload the excel file (using the button with the paperclip icon) so that we can try to reproduce the error?
AA
AA am 18 Apr. 2022
Sheet 2 of the attached file.
Torsten
Torsten am 18 Apr. 2022
Bearbeitet: Torsten am 18 Apr. 2022
And did you check the data from your sheet whether they contain Inf or Nan values as MATLAB told you to do ?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Voss
Voss am 18 Apr. 2022

1 Stimme

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,:));
94.0000 1.1390 11.5054 12.6866 95.0000 1.1100 11.0665 12.6872 96.0000 1.0810 11.5004 12.8538 97.0000 1.0530 11.5735 12.8539 98.0000 1.0270 11.5735 12.8545 99.0000 1.0010 11.5011 13.0211 100.0000 0.9753 11.5776 13.0212 NaN NaN 11.1309 13.0217 NaN NaN 11.4958 13.1884 NaN NaN 11.5716 13.1885 NaN NaN 11.1290 13.1890 NaN NaN 11.5058 13.3557 NaN NaN 11.5829 13.3558 NaN NaN 11.1383 13.3563 NaN NaN 7.9365 16.0230 NaN NaN 7.9187 16.0231
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)

2 Kommentare

AA
AA am 18 Apr. 2022
Thank you so much!
Voss
Voss am 18 Apr. 2022
You're welcome! If you have any questions let me know. Otherwise, if my answer works, please click 'Accept this Answer'. Thanks!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Interpolation of 2-D Selections in 3-D Grids finden Sie in Hilfe-Center und File Exchange

Gefragt:

AA
am 18 Apr. 2022

Kommentiert:

am 18 Apr. 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by