extracting matrices from text file

7 ビュー (過去 30 日間)
Ali
Ali 2023 年 8 月 17 日
回答済み: Cris LaPierre 2023 年 8 月 17 日
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]

回答 (1 件)

Cris LaPierre
Cris LaPierre 2023 年 8 月 17 日
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.

カテゴリ

Help Center および File ExchangeVariables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by