필터 지우기
필터 지우기

TABLE OF 2 ROWS AND 12 COLUMNS

조회 수: 6 (최근 30일)
F.O
F.O 2017년 10월 10일
댓글: Walter Roberson 2017년 10월 11일
Hi,I want to make a TABLE OF 2 ROWS AND 12 COLUMNS WITH YEAR IN THE FIRST ROW AND NUMBER OF EARTHQUAKES IN THE SECOND ROW.
year=[2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 ];
n_of_earthquakes=[1 2 4 0 1 1 1 2 2 1 1 0]

채택된 답변

Image Analyst
Image Analyst 2017년 10월 11일
You can't have a table like that. You can however have them in columns:
year=[2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 ];
n_of_earthquakes=[1 2 4 0 1 1 1 2 2 1 1 0]
t = table(year', n_of_earthquakes', 'VariableNames', {'year', 'n_of_earthquakes'})
If you want a matrix (a regular double numerical array) rather than a "table" variable, you can just use seimcolon:
m = [year; n_of_earthquakes]
  댓글 수: 1
F.O
F.O 2017년 10월 11일
Thanks ,this looks good.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2017년 10월 10일
year = 1973 : 1984;
earthquakes = randi(10000, 1, 12);
YourTable = array2table([year; earthquakes], 'RowNames', {'year', '# earthquakes'})
  댓글 수: 6
F.O
F.O 2017년 10월 11일
편집: Walter Roberson 2017년 10월 11일
Thanks a lot and this was what i wanted eventhough I didn't know what is this command
ylab = arrayfun( @(Y) sprintf('yr%d', Y), year, 'uniform', 0);
Walter Roberson
Walter Roberson 2017년 10월 11일
That command take the vector year, and for each element of it, applies the function @(Y) sprintf('yr%d', Y) . That function converts the numeric element to a string and puts the characters 'yr' in front of that, giving a character vector as a result for each numeric element. The 'uniform', 0 option tells MATLAB to put the results into a cell array, so the end result stored in ylab is a cell array, each element of which is a character vector that starts with 'yr' and then followed by the year.
Starting in R2017a, the entire line can be replaced with
ylab = "yr" + year;

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Earthquake Engineering에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by