Need help in creating a code

8 Ansichten (letzte 30 Tage)
Jack Wallard
Jack Wallard am 12 Mai 2021
Beantwortet: Steven Lord am 13 Mai 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 Kommentare
Jack Wallard
Jack Wallard am 13 Mai 2021
Is there a way to change this? I just want it to show 1985 instead of 0.1985. If you run the codes thats what comes out please help
Displaying new population data for given years
year, population
1.0e+04 *
0.1985 0.8721
0.1986 0.8980
0.1987 0.9247
0.1988 0.9524
0.1989 0.9811
0.1990 1.0112
0.1991 1.0428
0.1992 1.0760
0.1993 1.1110
0.1994 1.1481
0.1995 1.1873
Rik
Rik am 13 Mai 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.

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Walter Roberson
Walter Roberson am 12 Mai 2021
function n_pop=cencus(n_year)
^^^^^^
Spelling.

Steven Lord
Steven Lord am 13 Mai 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

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by