データフレーム型を条​件抽出して,時系列デ​ータの作り方

6 views (last 30 days)
tatuya
tatuya on 1 Apr 2023
Edited: covao on 23 Apr 2023
下のデータフレーム型のデータにおいて,8以下の要素だけ抽出したいのですが,コードの打ち方がわかりません.
教えていただければ幸いです.

Answers (1)

covao
covao on 23 Apr 2023
Edited: covao on 23 Apr 2023
MATLABの場合、find関数で条件を満たす配列要素を抽出できます。
% 6列、10行のTable型データ作成、1から20までの乱数
dataTable = array2table(rand(10, 6)*20)
dataTable = 10×6 table
Var1 Var2 Var3 Var4 Var5 Var6 _______ ______ ______ ______ ______ ______ 12.785 10.717 3.8291 4.4161 9.0192 16.807 7.8195 2.6859 5.9818 19.069 5.5469 4.8465 8.9907 1.8048 17.86 4.9735 5.1512 19.285 19.411 7.2609 14.199 2.9214 17.712 11.963 16.234 4.0493 6.9206 1.5388 18.19 3.4023 5.0571 10.424 2.7951 16.252 1.5601 3.0967 6.8913 19.987 5.6987 3.3618 2.078 14.58 0.51925 15.936 9.1296 7.4153 7.3528 3.3655 2.6528 2.0773 15.898 13.82 4.7566 19.249 6.6651 8.2614 6.0611 3.1514 2.0635 6.5425
% 8以下のデータがある要素を抽出
dataArray = table2array(dataTable);
p = find( dataArray <= 8);
newData = dataArray(p)'
newData = 1×36
7.8195 5.0571 6.8913 0.5192 2.6528 6.6651 2.6859 1.8048 7.2609 4.0493 2.0773 3.8291 5.9818 6.9206 2.7951 5.6987 6.0611 4.4161 4.9735 2.9214 1.5388 3.3618 7.4153 3.1514 5.5469 5.1512 1.5601 2.0780 7.3528 4.7566
% 抽出した要素以外をNaNに置き換え
newVar = NaN(size(dataArray));
newVar(p) = dataArray(p);
newTable = array2table(newVar)
newTable = 10×6 table
newVar1 newVar2 newVar3 newVar4 newVar5 newVar6 _______ _______ _______ _______ _______ _______ NaN NaN 3.8291 4.4161 NaN NaN 7.8195 2.6859 5.9818 NaN 5.5469 4.8465 NaN 1.8048 NaN 4.9735 5.1512 NaN NaN 7.2609 NaN 2.9214 NaN NaN NaN 4.0493 6.9206 1.5388 NaN 3.4023 5.0571 NaN 2.7951 NaN 1.5601 3.0967 6.8913 NaN 5.6987 3.3618 2.078 NaN 0.51925 NaN NaN 7.4153 7.3528 3.3655 2.6528 2.0773 NaN NaN 4.7566 NaN 6.6651 NaN 6.0611 3.1514 2.0635 6.5425

Categories

Find more on 環境と設定 in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!