extracting matrices from text file

4 Ansichten (letzte 30 Tage)
Ali
Ali am 17 Aug. 2023
Beantwortet: Cris LaPierre am 17 Aug. 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]

Antworten (1)

Cris LaPierre
Cris LaPierre am 17 Aug. 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.

Kategorien

Mehr zu Variables finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by