extracting matrices from text file

4 vues (au cours des 30 derniers jours)
Ali
Ali le 17 Août 2023
Hi everyone,
I want to extract matrices from Text file and read them as a data then split the data to %80 and %20.
I wrote this code to extract the data from the text file; however i still stuggling to split the data
clear all; close all; clc;
X = fileread("data_collection13.txt");
PT = regexp(X, '(?<=\[).*?(?=\])', 'match');
PV = cellfun(@(txt) textscan(txt, '', 'collectoutput', true), PT);
M=cell2mat(PV)
and here is a sample for the data
M1 = [5.5148 0.0000 0.0000 0.0000
0.0000 5.8713 3.1225 2.8308
0.0000 3.1225 3.7475 3.4559
0.0000 2.8308 3.4559 3.4559]
M2 = [5.5148 0.0000 0.0000 0.0000
0.0000 5.8713 3.1225 2.8309
0.0000 3.1225 3.7475 3.4559
0.0000 2.8309 3.4559 3.4559]
M3 = [5.5147 0.0000 0.0000 0.0000
0.0000 5.8712 3.1225 2.8308
0.0000 3.1225 3.7475 3.4558
0.0000 2.8308 3.4558 3.4558]

Réponses (1)

Cris LaPierre
Cris LaPierre le 17 Août 2023
I'd read the data into a matrix, and then use cvpartition to split it. See the examples on the linked page for more on how to accomplish an 80/20 split.

Catégories

En savoir plus sur Variables dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by