Cody keeps throwing the error "Error using SharedVariable1 (line 11) Assertion failed." no matter what code is submitted.
Seems the test suite always calls the function with the same cell array 'Day Temp' ' 1 1.3' ' 2 1.12' ' 3 17' ' 4 -32' ' 5 13' ' 6 4.4' ' 7 19'.
I have fixed an issue with this problem where the test suite was not visible since there was no %% for the first test suite
keeps throwing Error for me too. Even though the answers are I get are the same as the test suite.
I suggest that there should have been some cases with more than one 'run' of 9999 values in the Test Suite, just as in the "real-world data". For example: clean for an input based on [100 100 9999 9999 100 200 9999 300 500], which has two (not three) 'runs'. (Testing interpolation with nil slope, as in this example, would also have been good to include.)
the problem makes you sweat, awesome!
This is working still would be appreciated for enhancement.
function t = read_and_interp(s)
s=strtrim(s);
row_num=numel(s);
counter=1;
for i=2:row_num
splitted=strsplit(s{i});
temp1=splitted(1);
temp2=splitted(2);
r(counter)=str2double(temp1);
r(counter+1)=str2double(temp2);
counter=counter+2;
end
first_column=r(1:2:end)
second_column=r(2:2:end)
if find(second_column==9999)>=1
first_column(find(second_column==9999))=[];
missed=find(second_column==9999);
second_column(find(second_column==9999))=[];
missed_value=interp1(first_column,second_column,missed)
second_column=r(2:2:end);
second_column(find(second_column==9999))=missed_value;
t=second_column
else
t=second_column
end
Good Problem
beware of splitting.
solution:
https://github.com/AhmedNazir/MatlabCody/blob/master/read_and_interp.m
my code,can improve
function t = read_and_interp(s)
s(1) = [];
for i = 1:numel(s)
s{i} = str2num(s{i});
end
s = cell2mat(s);
c_2 =s(:,2)';
index_m = find(c_2 == 9999);
if isempty(index_m)
t=c_2;
else
num_m = numel(index_m);
inter = (c_2(index_m(end)+1)-c_2(index_m(1)-1))/(num_m+1);
for i = 1:num_m
c_2(index_m(i)) = c_2(index_m(i)-1)+inter;
end
t =c_2;
end
end
This made me realize I need to learn more about cells!
This solution actually fails on the assertion when using the following test (my own). It happens because of computational precision produced from using linspace() // out by about 0.222 * 1.0e-15.
s = { ...
'Day Temp'
' 1 1.3'
' 5 9999'
' 6 9999'
' 5 9999'
' 6 9999'
' 2 1.12'
' 3 17'
' 4 16'
' 5 9999'
' 6 9999'
' 7 19'};
t_correct = [1.3 1.264 1.228 1.1920 1.156 1.12 17 16 17 18 19];
assert(isequal(read_and_interp(s),t_correct));
my standalone MATLAB function works just fine -- but cody complains by
"Error using SharedVariable1 (line 11)
Assertion failed."
I cannot make heads or tails of it. Any help?
Check the test suite. There was an issue with the displaying of test suite.
Sorry about all the incorrect solutions just before this, but Cody was throwing errors that my Matlab installation wasn't.
Find all elements less than 0 or greater than 10 and replace them with NaN
13745 Solvers
1509 Solvers
Find out missing number from a vector of 9 elements
256 Solvers
580 Solvers
413 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!