我会评论你的代码,这样你就可以看到发生了什么。
另外,我建议添加(出于调试目的)另外两个显示,以便您了解发生了什么。
%# uigetfile reads the name of a file and stores it in file_input, for example 'mydata.dat'
[file_input,pathname] = uigetfile( ...
{'*.txt', 'Text (*.txt)'; ...
'*.xls', 'Excel (*.xls)'; ...
'*.*', 'All Files (*.*)'}, ...
'Select files');
disp(file_input)
%# fileparts splits file_input into name and extension. pathstr is empty, name is 'mydata',
%# ext is '.dat', and versn is empty
[pathstr, name, ext, versn] = fileparts(file_input)
disp(name)
%# name is a string containing, in our example, 'mydata'
%# r is the number of rows in the string 'mydata', which is 1
%# c is the number of columns in the string 'mydata', which is 6
r = size(name,1);
c = size(name,2);
disp(r)
disp(c)
如果你想要数据集的大小,你需要先加载数据集。
或者,如果您的数据集始终具有固定数量的列,例如,您可以尝试根据文件大小估计行数
%# get the file size (and other information about the file) using dir
d = dir(fullfile(pathname,file_input));
%# if the header contains, say, 10 bytes, and each row is 8 bytes, you find the number of rows
%# as follows
headerBytes = 10;
rowBytes = 8;
nRows = (d.size-headerBytes)/rowBytes;