小编way*_*vee的帖子

在matlab中将dat文件读入矩阵,每行有不同的数据量

我正在尝试编写一个将数据加载到矩阵中的matlab函数.问题是数据每行有一个值.所以我不能使用加载,所以我试图使用fgetl.

数据看起来像:

143234 
454323 354654
543223 343223 325465
Run Code Online (Sandbox Code Playgroud)

等等

我所做的是创建一个零矩阵,维度是高度和最长的数据串.为了将数据放入矩阵,我使用fgetl读取每一行,然后使用textscan在空白处分割数据.然后我使用str2num(我认为这是错误的地方)将字符串转换为数字.

首先是我的代码:

%READTRI Opens the triangle dat file and turns it into a matrix

fid = fopen('triangledata.dat');

%create matrix of zeros for the data to be retrieved
trimat = zeros(15,15);

%Check to see if the file loaded properly
if fid == -1
disp('File load error')
else
%if it does, continue

%read each line of data into a
while feof(fid) == 0

    %run through line by line
    aline = fgetl(fid);

    %split aline …
Run Code Online (Sandbox Code Playgroud)

file-io matlab matrix

2
推荐指数
1
解决办法
1893
查看次数

标签 统计

file-io ×1

matlab ×1

matrix ×1