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

Torsten
Torsten 2022년 4월 18일
편집: Torsten 2022년 4월 18일
And what' your problem ? Does your code not work ?
AA
AA 2022년 4월 18일
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 2022년 4월 18일
@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 2022년 4월 18일
Sheet 2 of the attached file.
Torsten
Torsten 2022년 4월 18일
편집: Torsten 2022년 4월 18일
And did you check the data from your sheet whether they contain Inf or Nan values as MATLAB told you to do ?

댓글을 달려면 로그인하십시오.

답변 (1개)

Voss
Voss 2022년 4월 18일

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,:));
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

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

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Interpolation of 2-D Selections in 3-D Grids에 대해 자세히 알아보기

태그

질문:

AA
2022년 4월 18일

댓글:

2022년 4월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by