how to Create 2D matrix in MATLAB and print it ?
4 views (last 30 days)
Show older comments
I want Matlab script to create a 2D array to print the results to me as follows
The data below is for virus corona for example
Reported Cases
Country No. Active case Recovered case Deaths Total
1 20598 135 1408 22141
2 33599 7927 3024 44550
3 27051 14656 2898 44605
4 50545 15824 682 67051
5 2161 76052 3305 81518
6 66969 19259 8189 94417
7 155753 5507 3175 164435
Total 356676 139360 22681 518717
The country UK has the minimum total cases: 22141
The country USA has the maximum total cases: 164435
The country Spain has the maximum deaths: 8189
The country UK has the minimum recovered cases: 135
0 Comments
Answers (1)
Ameer Hamza
on 27 Apr 2020
Edited: Ameer Hamza
on 27 Apr 2020
See table(): https://www.mathworks.com/help/matlab/tables.html to create such a data structure in MATLAB.
Also see summary() for tables: https://www.mathworks.com/help/matlab/ref/table.summary.html
1 Comment
emad xa
on 28 Apr 2020
can't use table
The coronavirus COVID-19 is affecting a number of countries. COVID-19 cases are classified as follows:
- Active case: a current case that is infected.
- Recovered case: a person who has recovered from the infection.
- Death: a person who was infected and died.
The collected data about countries are stored in two structures:
i) A column vector that contains the country names.
ii) A 2D matrix to represent the different cases. Each row contains the number of active cases, recovered cases and deaths for one country. The first row contains number of cases for the first country which has been stored in the column vector defined in (i). The data in the second row corresponds to the second country, and so on.
Write a Matlab script to do the following:
- Create the above structures and refer to the link https://www.worldometers.info/coronavirus/#countries to fill in recent data for some infected countries.
- Add to your 2D matrix a new column to store the total cases in each country. (Total cases in a country = active cases + recovered cases+ deaths). Also add a new row for the total active cases, recovered cases and deaths for all countries
- Print with appropriate header the 2D matrix as updated (b). The data should be sorted based on the total cases in each country. (Hint: Learn in Matlab documentation about sortrow())
- Find and print with appropriate message the following:
- The country which has the minimum total cases.
- The country which has the maximum total cases.
- The country which has the maximum deaths.
- The country which has the minimum recovered cases.
output
The output should be as follows:
Reported Cases
Country No. Active case Recovered case Deaths Total
1 20598 135 1408 22141
2 33599 7927 3024 44550
3 27051 14656 2898 44605
4 50545 15824 682 67051
5 2161 76052 3305 81518
6 66969 19259 8189 94417
7 155753 5507 3175 164435
Total 356676 139360 22681 518717
The country UK has the minimum total cases: 22141
The country USA has the maximum total cases: 164435
The country Spain has the maximum deaths: 8189
The country UK has the minimum recovered cases: 135
See Also
Categories
Find more on Web Services in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!