Sort Cell Array Data
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
clear all
close
F = xlsread('C:\Users\katie\Desktop\matlabhelp.csv')
t = F(:,1);
time = x2mdate(t,0);
date =datestr(time);
A = [date, F(:,2), F(:,3)];
dn = cellfun(@(x) datenum(x(1:11), 'dd-mmm-yyyy'), A);
[dns,ix] = sort(dn);
FinalSorted = A(ix);
An error occurs saying the following:
Error using cellfun
Input #2 expected to be a cell array,
was char instead.
Error in rough (line 12)
dn = cellfun(@(x) datenum(x(1:11),
'dd-mmm-yyyy'), A);
(Please note data is a small sample)
채택된 답변
Star Strider
2018년 4월 8일
1 개 추천
You haven’t stated the result you want.
Try this:
[F,S,R] = xlsread('Matlabhelp.csv');
t = F(:,1);
date = datetime(t, 'ConvertFrom','excel')
time = F(:,2)/24;
dv = [datenum(date) + time]
[dv_sort,idx] = sort(dv);
FinalSorted_1 = [datevec(dv_sort) F(idx,3)]
FinalSorted_2 = table(datetime(datevec(dv_sort)), F(idx,3))
FinalSorted_1 =
Columns 1 through 6
2017 12 21 12 1 12
2017 12 21 15 44 24
2017 12 28 23 45 0
2018 1 3 10 35 24
2018 1 16 11 1 12
Column 7
125.51
120.88
776
72.47
67.98
FinalSorted_2 =
5×2 table
Var1 Var2
____________________ ______
21-Dec-2017 12:01:12 125.51
21-Dec-2017 15:44:24 120.88
28-Dec-2017 23:45:00 776
03-Jan-2018 10:35:24 72.47
16-Jan-2018 11:01:12 67.98
댓글 수: 9
KPSil
2018년 4월 8일
I need to sort the dates into chronological order but it still needs to correspond to the same x and y.
Star Strider
2018년 4월 8일
I’ve no idea what ‘same x and y’ are.
Note that this sorts the third column of your data to correspond with the first (date) combined with the second (time of day) to create a date-and-time variable, and then uses the idx output of sort with them to assign the appropriate F(idx,3) variables to the output matrix.
The result of my code appears to sort the dates-and-times and data appropriately.
Star Strider
2018년 4월 9일
KPsil’s Answer moved here —
I’m sorry I haven’t explained myself very well.
The first column is the date. Second is x Third column is y.
Star Strider
2018년 4월 9일
I thought the second column was time.
With that clarification, this works:
[F,S,R] = xlsread('KPSil Matlabhelp.csv');
t = F(:,1);
date = datetime(t, 'ConvertFrom','excel')
% time = F(:,2)/24;
dv = datenum(date)
[dv_sort,idx] = sort(dv);
FinalSorted_1 = [datevec(dv_sort) F(idx,2:3)]
FinalSorted_2 = table(datetime(datevec(dv_sort)), F(idx,2:3))
KPSil
2018년 4월 9일
Thank you so much this works really well.
Star Strider
2018년 4월 9일
My pleasure.
If my Answer helped your solve your problem, please Accept it!
KPSil
2018년 4월 9일
I have now manipulated the data and have a new table with the date in form 'dd-mmm-yyyy' in first column and z in second column.
I need to have a cumulative sum of the z for each date, so I can plot the cumulative z score for each date.
e.g 01-Jan-2018 0.10 01-Feb-2018 0.32
Star Strider
2018년 4월 9일
See my Answer to your subsequent Question (that I just now posted).
I used your data from your earlier Question, so you will have to revise it slightly to work with your ‘z’ data.
KPSil
2018년 4월 14일
Please could you help with this problem?
https://uk.mathworks.com/matlabcentral/answers/394393-sorting-data-into-different-matrices-which-can-then-be-manipulated?s_tid=prof_contriblnk
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Time Series Objects에 대해 자세히 알아보기
제품
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
