Put Strings in a column

18 Ansichten (letzte 30 Tage)
heidi pham
heidi pham am 29 Okt. 2018
Bearbeitet: Adam Danz am 1 Dez. 2018
Hello,
I am trying to make a table like the following code.
But when I type my code, countries in each column could not be on the same vertical line like this. Specifically, I have to adjust each time I type a country to make sure for example, 1.Algeria and 9. ChinaHK,...are on the same vertical line, especially 1. and 9. are on exactly the same vertical line.
Could any one please show me how to make them on a vertical line (how to make a column of strings) without using space or tab in the keyboard to adjust?
Thank you,
Countries=[ '1.ALGERIA '; '2.ARGENTINA '; '3.AUSTRALIA '; '4.AUSTRIA '; '5.BELUXNE ';'6.BRAZIL '; '7.CANADA '; '8.CHILE ';
'9.CHINAHK '; '10.COLOMBIA '; '11.DENMARK '; '12.EGYPT '; '13.FINLAND ';'14.FRANCE '; '15.GERMANY '; '16.GREECE ';
'17.INDIA '; '18.INMYSGTH '; '19.IRELAND '; '20.ISRAEL '; '21.ITALY ';'22.JAPAN '; '23.KOREA '; '24.MEXICO ';
'25.NEWZEALAND '; '26.NORWAY '; '27.PAKISTAN '; '28.PERU '; '29.PHILIPPINES ';'30.PORTUGAL '; '31.RUSSIA '; '32.SOUTHAFRICA ';
'33.SPAIN '; '34.SWEDEN '; '35.SWITZERLAND '; '36.TURKEY '; '37.UK ';'38.US '; '39.VENEZUELA '; '40.ROW ']

Antworten (2)

Gravey
Gravey am 30 Okt. 2018
Bearbeitet: Gravey am 30 Okt. 2018

Hi,

I think I would create a separate column for each of the countries you want stacked underneath each other vertically, and then save these as a table at the end. Something like this;

Countries1 = {'1.Algeria';'9.ChinaHK';'17.India'}
Countries2 = {'2.Argentina';'10.Columbia';'18.Inmysgth'}
Countries3 = {'3.Australia';'11.Denmark';'19.Ireland'}        
Countries = table(Countries1,Countries2,Countries3)
  1 Kommentar
heidi pham
heidi pham am 31 Okt. 2018
thank you, that seems very smart.
the codes i posted in the question are taken from a published paper, so I just a bit curious how can they put the countries in a very precise way for each column.
But thank you a lot for suggesting a way!

Melden Sie sich an, um zu kommentieren.


Adam Danz
Adam Danz am 1 Dez. 2018
Bearbeitet: Adam Danz am 1 Dez. 2018
First convert to a cell array (you must use curly brackets). That will result in a single column. Then use reshape() and transpose the array to get exactly what you want.
Countries={ '1.ALGERIA '; '2.ARGENTINA '; '3.AUSTRALIA '; '4.AUSTRIA '; '5.BELUXNE ';'6.BRAZIL '; '7.CANADA '; '8.CHILE ';
'9.CHINAHK '; '10.COLOMBIA '; '11.DENMARK '; '12.EGYPT '; '13.FINLAND ';'14.FRANCE '; '15.GERMANY '; '16.GREECE ';
'17.INDIA '; '18.INMYSGTH '; '19.IRELAND '; '20.ISRAEL '; '21.ITALY ';'22.JAPAN '; '23.KOREA '; '24.MEXICO ';
'25.NEWZEALAND '; '26.NORWAY '; '27.PAKISTAN '; '28.PERU '; '29.PHILIPPINES ';'30.PORTUGAL '; '31.RUSSIA '; '32.SOUTHAFRICA ';
'33.SPAIN '; '34.SWEDEN '; '35.SWITZERLAND '; '36.TURKEY '; '37.UK ';'38.US '; '39.VENEZUELA '; '40.ROW '};
CountriesArray = reshape(Countries, 8, 5)';
181201 165240-MATLAB R2018a - academic use.jpg

Community Treasure Hunt

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

Start Hunting!

Translated by