Put Strings in a column

18 ビュー (過去 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 Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by