MATLAB ONLY:
Find oldest house on the market?
can't not use any built in function except length and isnan to write this function if necessary .
Inputs:
dateConstruct - an array that will be linked to when each house was build
dateRebuild - an array that will be linked to when eeach house was rebuild. However if an house has never been rebuild, the year will be Nan.
Outputs:
Numb - will serve as the index location for the oldest standing house in the neighborhood.
Example: DateConstruct= [ 2025 2030 2015]; dateRebuild = [ 2030 Nan 2056]
then ind = [1, 2] because their is a tie for the oldest house standing. should also be able to display if its just 1 house or two without an issue.
function [Numb] = Oldesthouse(dateConstruct, dateRebuild)
%write your code below
end
Code to call your function
dateConstructBig = [ 2070,2026,2062,2063,2021,2015,2062,2006,2037,2037,2064,2056,2026,2026];
dateRebuildBig= [3007,3002,2090,3000,2098,Nan, 2089,Nan,2081,2097,2099,2083,2083];
[Numb] = Oldesthouse(dateConstructBig, dateRebuildBig)
disp("oldest house location is:" + Numb)
function [Numb] = Oldesthouse(dateConstruct, dateRebuild)
dateRebuild(isnan(dateRebuild))=dateConstruct(isnan(dateRebuild));
oldest=dateRebuild(1);
for i=1:length(dateConstruct)
if dateRebuild(i)<oldest
oldest=dateRebuild(i);
end
end
indices=1:length(dateConstruct);
Numb=indices(dateRebuild==oldest);
end
Get Answers For Free
Most questions answered within 1 hours.