Put Strings in a column

조회 수: 7 (최근 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