Read text file in MATLAB
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
fendertunes
le 3 Juil 2016
Commenté : Azzi Abdelmalek
le 3 Juil 2016
Hi,
I have a .txt file with lots of lines of text in the following format -
18400 8510.27+j8207.84
19200 1336.93+j3261.25
20000 14176.3+j11725.7
I would like to read this in matlab and plot it. How can I do it?
I have tried converting the .txt to .xlsx and using xlsread function -
[col1, col2] = xlsread('myfile.xlsx');
But the result is a double and a cell matrix. I can't treat cell as a number to plot.
Also the length of rows in the .txt file could vary (could be 100 rows, couple be 10,000 rows). Is there a way to read the numbers? I am ok with creating temporary variables, using repmat or doing str2num conversion. However, I haven't figured out a way to do it so far.
0 commentaires
Réponse acceptée
Azzi Abdelmalek
le 3 Juil 2016
Modifié(e) : Azzi Abdelmalek
le 3 Juil 2016
M=importdata('yourfile.txt')
a=regexp(M,'\S+','match');
b=strrep([a{:}],'j','j*')
c=str2double(b)
out=reshape(c,[],2)
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Text Files dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!