フィルターのクリア

Grab tempretures higher than 299

4 ビュー (過去 30 日間)
Shawntae Harris
Shawntae Harris 2020 年 8 月 6 日
コメント済み: Walter Roberson 2020 年 8 月 9 日
I have made this program that grabs tempretures from a text file while ignoring the other characters in the cell to plot but i only grab temps from 200-299 and I want to expand
clear all; close all; clc;
%read data from the text file by
%insert your textfile to open
file = fopen('rocks1.txt', 'rt');
%put file data into array
raw = textscan(file,'%s');
txt = raw{1,1};
%extract only numbers from array
temps = regexp(txt, '(\w*2)[\d.]+', 'match');
%regexp only reads 200K to 299K, need to go higher
strdata = temps(~cellfun('isempty',temps));
%turn string into number
numdata = [];
numdata = cellfun(@str2double,strdata);
%plot
time = 1:length(numdata);
plot(time,numdata)
xlabel('Time (s)')
ylabel('Temp (K)')
  1 件のコメント
Walter Roberson
Walter Roberson 2020 年 8 月 9 日
temps = regexp(txt, '(\w*2)[\d.]+', 'match');
That does not match only numbers. The \w part matches any number of "word building" characters, which are the digits, the lower-case and upper case letters, the underscore, and a bunch of interational characters such as ªµºÀÁÂÃÄÅÆÇ
The pattern would, for example, match all of ABCD234 . And the str2double() would fail on that.
It would probably make more sense to use '\<[\d.]+'

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

採用された回答

Raunak Gupta
Raunak Gupta 2020 年 8 月 9 日
Hi,
For going values greater than 299K you can change the text according to the range in regexp. For example if you want to cover values from 300-399K also, you can change the regexp expression to something like below.
temps = regexp(txt, '(\w*[2-3])[\d.]+', 'match');
Above expression will find values between 200-399K.
You can follow the expression definition for creating an expression for your case.
  1 件のコメント
Shawntae Harris
Shawntae Harris 2020 年 8 月 9 日
Thanks alot!

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

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by