- Goncharov
- 文章數 : 2
積分 : 6
注冊日期 : 2020-05-19
Given an input cell array of strings s, pick out the second column and turn it into a row vector of data. Missing data will be indicated by the number 9999. If you encounter missing data, you should perform linear interpolation to the nearest accurate data points (missing data will not occur in the first or last element). The first row is always descriptive text. So if the input cell array s is S . "Day Temp 1 -5 . 2 19 3 1 4 9999 5 3' ); then the output variablet is the following row vector, 1 t - [-5 19 1 2 3]; Here's an example of real-world data, Solution MATLAB Documentation 1 function t = read_and_interp(s) 3 end
Test Code Input %% Day Temp 1.3' 1.12 17 -32 OWN 6 4.4 7 19'}; t_correct = [1.3 1.12 17 -32 13 4.4 19): assert(isequal(read_and_interp(s),t_correct)); 'Day Temp 1 1.3 2 1.12 3 17 . 4 16' 5 9999 6 9999 7 19'}; t_correct - [1.3 1.12 17 16 17 18 19]; assert(isequal(read and interp(s), t_correct));
S = - Day Temp 1 -5 + 2 19 - 1 4 9999 53'}; t_correct = [-5 19 1 2 3]; assert(isequal(read_and_interp(s),t_correct));
Test Code Input %% Day Temp 1.3' 1.12 17 -32 OWN 6 4.4 7 19'}; t_correct = [1.3 1.12 17 -32 13 4.4 19): assert(isequal(read_and_interp(s),t_correct)); 'Day Temp 1 1.3 2 1.12 3 17 . 4 16' 5 9999 6 9999 7 19'}; t_correct - [1.3 1.12 17 16 17 18 19]; assert(isequal(read and interp(s), t_correct));
S = - Day Temp 1 -5 + 2 19 - 1 4 9999 53'}; t_correct = [-5 19 1 2 3]; assert(isequal(read_and_interp(s),t_correct));
- Christopher N.Contributor
- 文章數 : 16
積分 : 18
注冊日期 : 2020-05-01
function t = read_and_interp(s)
temp=zeros(1,length(s)-1);
day=temp;
for i = 2:length(s)
tokens=split(strip(s{i}));
day(i-1)=str2double(tokens{1});
temp(i-1)=str2double(tokens{2});
end
t=temp;
for i=2:length(t)-1
if t(i)==9999
last=1;
while t(i-last)==9999
last=last-1;
end
next=1;
while t(i+next)==9999
next=next+1;
end
newX=day(i);
t(i)=t(i-last)+(newX-day(i-last))*(t(i+next)-t(i-last))/(day(i+next)-day(i-last));
end
end
end
temp=zeros(1,length(s)-1);
day=temp;
for i = 2:length(s)
tokens=split(strip(s{i}));
day(i-1)=str2double(tokens{1});
temp(i-1)=str2double(tokens{2});
end
t=temp;
for i=2:length(t)-1
if t(i)==9999
last=1;
while t(i-last)==9999
last=last-1;
end
next=1;
while t(i+next)==9999
next=next+1;
end
newX=day(i);
t(i)=t(i-last)+(newX-day(i-last))*(t(i+next)-t(i-last))/(day(i+next)-day(i-last));
end
end
end
這個論壇的權限:
您 無法 在這個版面回復文章