フィルターのクリア

How to ignore last letter in a cell containing text and numbers

1 回表示 (過去 30 日間)
Jack Lakeman
Jack Lakeman 2018 年 10 月 17 日
コメント済み: Jack Lakeman 2018 年 10 月 17 日
Hi there,
So I have a space separated text file and im trying to alter this piece of code "tmp=textscan(tmpl,'%s %s %s %s %s')" so that matlab only reads "4.259" and not "4.259M"
11- Number yyyy mm dd hh mi ssf f f
12- 1) 2017/01/01 00:00:00 4.259M 0.053M
Code:
function data=load_tide_data(filename)
data.filename=filename;
fid=fopen(filename);
for I=1:12
tmpl=fgetl(fid);
end
J=1;
while ischar(tmpl)
tmp=textscan(tmpl,'%s %s %s %s %s');
data.t(J)=datenum([ cell2mat(tmp{2}) ' ' cell2mat(tmp{3}) ]);
tmph=str2num(cell2mat(tmp{4}));
if isempty(tmph)
tmph=NaN;
end
data.h(J)=tmph;
tmpl=fgetl(fid);
J=J+1;
end
fclose(fid)
Any ideas would be greatly appreciated :)
  4 件のコメント
jonas
jonas 2018 年 10 月 17 日
編集済み: jonas 2018 年 10 月 17 日
An ugly solution would be to add M as a delimiter and use multipledelimsasone, the downside being that it would interpret all letters M as delimiters..
Jack Lakeman
Jack Lakeman 2018 年 10 月 17 日
Not only that but i have different files where the "M" is dotted around in different cells. So some would have an M and some wont in the same file

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeString Parsing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by