入出館のデータから滞在人数のグラフを作る方法

3 次查看(过去 30 天)
Kazu Ari
Kazu Ari 2023-6-1
评论: Kazu Ari 2023-6-6
添付csvの入出館のデータから、滞在人数の線グラフ(横軸10分単位の時間、縦軸滞在人数)を作ることはできるでしょうか?
1日悩んだのですが、どうにも判りません。(もしかしたら出来ないのかも)
よろしくお願いいたします。

采纳的回答

Atsushi Ueno
Atsushi Ueno 2023-6-1
isbetween 関数を使えば、日付と時刻の区間内の要素を判別出来ます。
data = readtable('https://jp.mathworks.com/matlabcentral/answers/uploaded_files/1399879/Book1.csv');
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table. The original column headers are saved in the VariableDescriptions property.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.
for k = 1:height(data) % 入退室それぞれの日付と時刻をくっ付ける(もっと上手いやり方があるはず)
data2(k,1) = datetime(strcat(string(data{k,1})," ",string(data{k,2})),'InputFormat','yyyy/MM/dd HH:mm:ss');
data2(k,2) = datetime(strcat(string(data{k,3})," ",string(data{k,4})),'InputFormat','yyyy/MM/dd HH:mm:ss');
end
number = [];
for tm = min(data2(:)):minutes(10):max(data2(:)) % 10分おきに何人居るか数える
number = [number sum(isbetween(tm,data2(:,1),data2(:,2)))];
end
stairs(min(data2(:)):minutes(10):max(data2(:)),number); % 階段状の線プロット
  3 个评论
Atsushi Ueno
Atsushi Ueno 2023-6-2
プログラムを見直し for 文を除去等、上手いやり方にしました。MATLABで for 文使ったら負け🤔
data = readtable('https://jp.mathworks.com/matlabcentral/answers/uploaded_files/1399879/Book1.csv');
data2 = datetime(data{:,[1 3]},'InputFormat','yyyy/MM/dd') + data{:,[2 4]}; % 入退室それぞれの日付と時刻をくっ付ける
tmslc = min(data2(:)):minutes(10):max(data2(:)); % 10分おきのタイムスライス
number = sum(isbetween(tmslc,data2(:,1),data2(:,2))); % 何人居るか数える
stairs(tmslc,number); % 階段状の線プロット
Kazu Ari
Kazu Ari 2023-6-6
有難うございます。
「MATLABでfor文をつかったら負け」
これが気になってしまい、他で作成中のスクリプトの見直しに入ってしまいました。
VBAから始めたのでどうしてもfor文を使ってしまうんですよね。

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 2 次元および 3 次元プロット 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!