MATLAB Answers

Need help in creating a code

33 views (last 30 days)
Jack Wallard
Jack Wallard on 12 May 2021
Answered: Steven Lord on 13 May 2021
A town has a population census every 10 years. The results of the census are shown below. Create a spreadsheet and MATLAB Script that to return the estimation of the value of the population of the town for any year between 1900 and 2000.Make your script interactive in case there is a change in data.
  9 Comments
Rik
Rik on 13 May 2021
What syntax are you using in fprintf? Or are you still using disp? If you want a specific format, you should not be using disp.

Sign in to comment.

Answers (2)

Walter Roberson
Walter Roberson on 12 May 2021
function n_pop=cencus(n_year)
^^^^^^
Spelling.

Steven Lord
Steven Lord on 13 May 2021
Change the format you use to display the data.
year=[1900:10:2000];
pop=[550 720 1265 2287 2756 3012 4086 5220 7478 10112 14226];
n_year = 1955:3:1995;
n_pop= interp1(year, pop, n_year,'spline');
format % use the default display format
data = [n_year.', n_pop.']
data = 14×2
1.0e+04 * 0.1955 0.3502 0.1958 0.3860 0.1961 0.4189 0.1964 0.4480 0.1967 0.4799 0.1970 0.5220 0.1973 0.5794 0.1976 0.6484 0.1979 0.7228 0.1982 0.7972
format longg % use a different format
data
data = 14×2
1955 3501.6750103553 1958 3859.51906774669 1961 4189.48262780744 1964 4480.27168483063 1967 4799.11598356959 1970 5220 1973 5794.44895199742 1976 6484.15102503682 1979 7228.335146493 1982 7971.59789248895
You could even create a table array of your data.
T = table(n_year.', n_pop.', 'VariableNames', {'Year', 'Population'})
T = 14×2 table
Year Population ____ ________________ 1955 3501.6750103553 1958 3859.51906774669 1961 4189.48262780744 1964 4480.27168483063 1967 4799.11598356959 1970 5220 1973 5794.44895199742 1976 6484.15102503682 1979 7228.335146493 1982 7971.59789248895 1985 8720.93475584499 1988 9523.59859499264 1991 10427.5132244569 1994 11480.6024587629

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!