Help using logic to edit table

4 ビュー (過去 30 日間)
Kristine
Kristine 2025 年 4 月 8 日
コメント済み: VBBV 2025 年 4 月 8 日

Hi,

I have a table indicating when high and low tides occur. I am trying to split the table in two: creating a table with only high tide information, and another table with only low tide information. There is a column in my main table that has either the letter H or L indicating high or low tides. There might be a better way to do this, and if so please feel free to share — my approach is to duplicate the main table and delete the rows associated with either H or L. I wrote the following code, but it does not work.

for row = 1:height(high_tides)
    if high_tides.High_Low == "L"
       high_tides(:) = []
    end
end

Can someone tell me what I’m doing wrong? Or is there a better way to go about this?

Thank you!

  1 件のコメント
VBBV
VBBV 2025 年 4 月 8 日
if you want to delete the specfic rows that match "L" then you can use row index as below
for row = 1:height(high_tides)
if strcmp(high_tides.High_Low,"L") % strcmp
high_tides(row,:) = [];
end
end
high_tides

サインインしてコメントする。

採用された回答

Paul
Paul 2025 年 4 月 8 日
T = table(["H";"L";"H";"L"],(1:4).','VariableNames',["Tide","Height"])
T = 4x2 table
Tide Height ____ ______ "H" 1 "L" 2 "H" 3 "L" 4
Thigh = T(T.Tide=="H",:)
Thigh = 2x2 table
Tide Height ____ ______ "H" 1 "H" 3
Tlow = T(T.Tide=="L",:)
Tlow = 2x2 table
Tide Height ____ ______ "L" 2 "L" 4
Or, if you want to duplicate the main table and then delete
Thigh = T;
Thigh(T.Tide=="L",:)=[]
Thigh = 2x2 table
Tide Height ____ ______ "H" 1 "H" 3
  1 件のコメント
Kristine
Kristine 2025 年 4 月 8 日
I was overcomplicating things, thank you.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by