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

3 vues (au cours des 30 derniers jours)
Kazu Ari
Kazu Ari le 1 Juin 2023
Commenté : Kazu Ari le 6 Juin 2023
添付csvの入出館のデータから、滞在人数の線グラフ(横軸10分単位の時間、縦軸滞在人数)を作ることはできるでしょうか?
1日悩んだのですが、どうにも判りません。(もしかしたら出来ないのかも)
よろしくお願いいたします。

Réponse acceptée

Atsushi Ueno
Atsushi Ueno le 1 Juin 2023
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 commentaires
Atsushi Ueno
Atsushi Ueno le 2 Juin 2023
プログラムを見直し 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 le 6 Juin 2023
有難うございます。
「MATLABでfor文をつかったら負け」
これが気になってしまい、他で作成中のスクリプトの見直しに入ってしまいました。
VBAから始めたのでどうしてもfor文を使ってしまうんですよね。

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur 2 次元および 3 次元プロット dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!