How to read different data types from a txt file

Hi all, How can I read this file and assign each line to a variable
USB
00000001
8
10000000111
128
0.0000008

 Accepted Answer

lines = strsplit(fileread('C:\somewhere\yourfile'), {'\r', '\n'});
lines will be a cell array with each cell containing a line of your text file.

2 Comments

You're going to have problems reading 80e-9 as integer!
Anyway
str2double(lines(2:end))
will convert all but the first line to real numbers.
Thanks a lot, I really appreciate your help <3
That's what worked for me:
lines= strsplit(fileread('USB_Config.txt'),{'\r', '\n'});
A=lines(1);
B=str2num((lines{2}.'));%Binary
C=lines(3);
D=str2num((lines{4}.'));%Binary
E=lines(5);
F=lines(6);

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2019b

Asked:

on 13 Dec 2019

Edited:

on 16 Dec 2019

Community Treasure Hunt

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

Start Hunting!