Error in reading text file and implemeting conditional logic to it
1 回表示 (過去 30 日間)
古いコメントを表示
I have 3 colums in my text file.The first 2 are numbers but the last one is mixed.I want to load them and then i want to process the third column so that when there is a variable 'any' it will show logic 1 and when there is some other number it will show a logic 0.In this way I want to create a matrix of 1 and 0.
The problem is I am not getting the roper values after using strcmp and the third column is not working properly. My code:
r=tdfread('Dummy.txt');
for rname = fieldnames(r)
things = r.(rname{3});
s1 = 'any';
for i=1:size(str,1)
a=str(i);
TF = strcmp(s1,a);
end
end
TF is only returning o which should not be the case.
I have attached the text file below
0 件のコメント
回答 (1 件)
Guillaume
2019 年 4 月 30 日
編集済み: Guillaume
2019 年 4 月 30 日
I don't have the stats toolbox and so have never used tdfread. You file can be easily read by readtable which doesn't require any toolbox:
t = readtable('ABC.txt');
t.C = strcmp(t.C, 'any') %change variable C into logical true if equal to 'any', false otherwise
edit: I've only just looked at the code you'd written. It's complete nonsense. This is what it should have been:
r=tdfread('Dummy.txt');
rname = fieldnames(r)
things = {r.(rname{3})};
TF = strcmp(things, 'any');
I'd still use tables for the job.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Text Data Preparation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!