Need to select specific values from text file depending of condition

2 ビュー (過去 30 日間)
Abha Thazhathe Peedika
Abha Thazhathe Peedika 2022 年 4 月 22 日
編集済み: Voss 2023 年 9 月 28 日
Im a beginner in MATLAB and i have a text file with date,shot and experiment type in three columns with a massive number of rows. I need to create a separate array with only specific values of shot numbers(column 2) corresponding to experiment type -standard(column 3==standard). Please suggest how i should go about this. Thank you in advance.
  3 件のコメント
Abha Thazhathe Peedika
Abha Thazhathe Peedika 2022 年 4 月 22 日
The whole text file has over 20000 rows but only very few in between are "standard shots" which i need to extract.
Mathieu NOE
Mathieu NOE 2022 年 4 月 22 日
hello
please share an extract of the file (zip it if possible)
tx

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

回答 (1 件)

Lokesh
Lokesh 2023 年 9 月 28 日
編集済み: Voss 2023 年 9 月 28 日
Hi Peedika,
I understand that you have a text file with three columns: date, shot, and experiment type and you want to extract the shot numbers (column 2) where the experiment type is "standard" (column 3 == "standard").
To achieve this, you can follow these steps:
  • Read the text file into a table using the readtable function.
  • Filter the table based on the condition that the experiment type is "standard".
  • Extract the shot numbers from the filtered table and store them in a separate array.
I have provided an example code snippet below that extracts specific values based on a condition:
% Set the path to the output text file
filePath = 'path_to_text_file';
% Read the text file
dataRead = readtable(filePath, 'Delimiter', '\t');
% Filter the data based on the experiment type ('standard')
filteredData = dataRead(dataRead.experiment_type == "standard", :)
% Extract the shot numbers from the filtered data
shotNumbers = filteredData.shot
Note: The assumed column names are 'date', 'shot', and 'experiment_type'.
You can refer to the below mentioned documentation to know more about the usage of “readtable:
I hope you find this helpful.

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

製品


リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by