Put Strings in a column

16 次查看(过去 30 天)
heidi pham
heidi pham 2018-10-29
编辑: Adam Danz 2018-12-1
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 ']

回答(2 个)

Gravey
Gravey 2018-10-30
编辑:Gravey 2018-10-30

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 个评论
heidi pham
heidi pham 2018-10-31
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!

请先登录,再进行评论。


Adam Danz
Adam Danz 2018-12-1
编辑:Adam Danz 2018-12-1
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

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by