Split numerical double array to multiple columns?

조회 수: 12 (최근 30일)
Kate
Kate 2017년 3월 22일
댓글: the cyclist 2017년 3월 23일
Hey guys,
I'm sure there's a simple workaround for this but I can't seem to find it. I have data with the following format
whos data
Name Size Bytes Class Attributes
data 1095x9 78840 double
data(1:10, 1)
ans =
20090101
20090102
20090103
20090104
20090105
20090106
20090107
20090108
20090109
20090110
It's currently in the format of yearmonthday, but I would like to pull them apart to look at year, month, day. How do I pull, for example, the first 4 numbers from a double array?

채택된 답변

the cyclist
the cyclist 2017년 3월 22일
Like this?
data = [
20090101
20090102
20090103
20090104
20090105
20090106
20090107
20090108
20090109
20090110]
year = floor(data/10000)
month = floor((data-year*10000)/100)
day = data-year*10000-month*100
  댓글 수: 2
Kate
Kate 2017년 3월 22일
Floor, thats what I was looking for, thanks! I was doing a bunch of num2str, str2num messiness. Thanks :)
the cyclist
the cyclist 2017년 3월 23일
Glad it helped. The best form of thanks is to upvote and/or accept answers that you've found helpful. This rewards the contributor, and can guide future users to helpful answers.

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

추가 답변 (1개)

Kate
Kate 2017년 3월 22일
Yep! This also works but it's very inefficient in my mind:
w=num2str(data(:, 1));
yr=str2num(w(:, 1:4))
month=str2num(w(:, 5:6));
day=str2num(w(:, 7:8));

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by