How to read Binary from a txt file and assign it to row vector

7 vues (au cours des 30 derniers jours)
Omar Ashraf
Omar Ashraf le 15 Déc 2019
Commenté : Omar Ashraf le 16 Déc 2019
How can I read each line and store it in an array?
txt file:
00001
1000111
0.923 %this is a float
I want to read them as:
A=[0 0 0 0 1]
B=[1 0 0 0 1 1 1]
C=0.923
  2 commentaires
Turlough Hughes
Turlough Hughes le 15 Déc 2019
Can you attach the file?
Omar Ashraf
Omar Ashraf le 15 Déc 2019
Modifié(e) : Omar Ashraf le 15 Déc 2019
Here's the file

Connectez-vous pour commenter.

Réponse acceptée

dpb
dpb le 15 Déc 2019
Will have to read as char() and convert. For the one record, first cell...
>> x=textscan(s,'%s %s %f');
>> A=str2num(char(x{1}).')
ans =
0
0
0
0
1
>>
If the fields are fixed length, you can play games with counted %c fields or you can do similar type punning on the file image directly in memory.

Plus de réponses (0)

Catégories

En savoir plus sur Data Import and Export dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by