Error in reading text file and implemeting conditional logic to it

1 visualización (últimos 30 días)
TRISHITA BANERJEE
TRISHITA BANERJEE el 30 de Abr. de 2019
Editada: Guillaume el 30 de Abr. de 2019
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

Respuestas (1)

Guillaume
Guillaume el 30 de Abr. de 2019
Editada: Guillaume el 30 de Abr. de 2019
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.

Categorías

Más información sobre Text Data Preparation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by