Sort Cell Array Data
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
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 日
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!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
