How do I slice a matrix by the values in a certain column?

조회 수: 9 (최근 30일)
Heidi Hirsh
Heidi Hirsh 2019년 4월 12일
답변: Oluwafemi 2024년 3월 11일
I have a large "master" table that I read in as a matrix. I wanted to create new matrices for each "height" value (there are 5: S, 1T, 10B, 4B, and 1B). Right now I have done this the "dumb" way by just sorting by height and creating new csv tables to read in but that is not a good solution at all. Is there a way to loop through the matrix and save all the rows for appropriate heights? (or another parameter that I want to group/sort by).
I have attached a screenshot of the table I am working with.
I hope you can understand my question. I am having a hard time putting what I want to do into words...
This is how I am reading in data so far...
weekly = readtable('MasterSampleLog_weekly_v1_withNO3.csv');
samples.SampleID = weekly.Sample_ID;
samples.TA = weekly.TA;
samples.DIC = weekly.DIC;
samples.Temp = weekly.Temperature;
samples.Sal = weekly.SAL;
samples.Height = weekly.height;
samples.PH = weekly.ph;
  댓글 수: 1
darova
darova 2019년 4월 12일
Look for strcmp(), regexp(). Use curly braces to select data in table (weekly{:,1})

댓글을 달려면 로그인하십시오.

답변 (1개)

Oluwafemi
Oluwafemi 2024년 3월 11일
B = [0.02,4.88,-3.21,2;0.56,3.9,-2.7,2;0.91,2.2,0.13,1;1.43,0.41,-1.02,3;0.00,1.9,-3.4,2;2.7,0.5,-4.0,3]
% to get the matrix where 4th column == 2
B(B(:,4)==2,:)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by