Effacer les filtres
Effacer les filtres

How can I save multiple matrices from text file?

1 vue (au cours des 30 derniers jours)
Liana Shpani
Liana Shpani le 25 Juin 2018
Commenté : Liana Shpani le 25 Juin 2018
I want to read dynamically all the particle path information for each particle. The number of matrices I need will vary according to how many particles are in the simulation. I separated the matrices with the word "Particle" as shown in the results.txt file I am attaching here.
Thank you in advance!

Réponse acceptée

Guillaume
Guillaume le 25 Juin 2018
There are many ways to do this, here is one option:
contents = fileread('results.txt'); %read whole file at once
contents = strsplit(contents, 'Particle'); %split into cell array at particle
particles = cellfun(@(c) sscanf(c, '%f', [3 Inf])', contents(2:end), 'UniformOutput', false); %scan each section into a 3xN matrix
  1 commentaire
Liana Shpani
Liana Shpani le 25 Juin 2018
That did it! Thank you so much!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Text Analytics Toolbox dans Help Center et File Exchange

Produits


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by