获取数据集matlab的大小,尺寸函数 [英] Get dimensions for dataset matlab, Size Function

查看:342
本文介绍了获取数据集matlab的大小,尺寸函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好我一直在试图显示数据集的维度,下面是我使用的以下matlab代码...但它给了我错误的输出....我行数和列值是错误的....关于这个问题的任何帮助将不胜感激

  [file_input,pathname] = uigetfile(... 
{'* .txt','Text(* .txt)'; ...
'* .xls','Excel(* .xls)'; ...
'*。 *','所有文件(*。*)'},...
'选择文件');

uiimport(file_input)

[pathstr,name,ext,versn] = fileparts(file_input)


r = size ,1);
c = size(name,2);
$ b $ disp(r)
disp(c)


首先,你需要将 file_input 路径名结合在一起来创建完整的路径到你想要的文件。你可以使用函数 FULLFILE : / p>

  dataFile = fullfile(pathname,file_input); 

其次,当您使用 UIIMPORT ,您可以选择想要将文件数据加载到的变量的名称。默认情况下,如果文件只包含一种类型的数据(即没有标题文本的数字),则变量名称是您加载的文件的名称,因此,如果不更改存储该变量的名称文件数据:

  uiimport(dataFile); %#加载数据
[filePath,fileName,fileExt] = fileparts(dataFile); %#获取文件名
dataSize = size(eval(fileName)); %#获取数据的大小
disp(dataSize(1)); %#显示行
disp(dataSize(2)); %#显示列

您也可以使用该选项从 UIIMPORT 作为数据存储在字段中的结构(以文件名作为默认字段名):

  dataStruct = uiimport(dataFile); %#把数据放在一个struct 
[filePath,fileName,fileExt] = fileparts(dataFile); %#获取文件名
dataSize = size(dataStruct。(fileName)); %#获取数据的大小
disp(dataSize(1)); %#显示行
disp(dataSize(2)); %#显示列

如果您需要将加载的数据传递给另一个函数,或者将其用于任何其他方式,您可以执行以下操作:

  some_other_fcn(eval(fileName)); %#当用UIIMPORT加载到一个变量
some_other_fcn(dataStruct。(fileName)); %#当用UIIMPORT加载到一个struct


Hello I have been trying to display the dimensions of a dataset, below is the following matlab code that i used...but it gives me the wrong output....i'e number of rows and columns values are wrong....any help regarding this issue would be highly appreciated

[file_input,pathname]  = uigetfile( ...
    {'*.txt', 'Text (*.txt)'; ...
    '*.xls', 'Excel (*.xls)'; ...
    '*.*', 'All Files (*.*)'}, ...
    'Select files');

    uiimport(file_input)

    [pathstr, name, ext, versn] = fileparts(file_input)


    r = size(name,1);
    c = size(name,2);

    disp(r) 
    disp(c)

解决方案

Firstly, you need to combine file_input and pathname together to create the full path to the file you want. You can do this with the function FULLFILE:

dataFile = fullfile(pathname,file_input);

Secondly, when you use UIIMPORT you can choose the name for the variable that you want the file data to be loaded into. By default, the variable name is the name of the file you loaded if your file contains only one kind of data (i.e. numbers with no header text), so the following should work if you don't change the name of the variable storing the file data:

uiimport(dataFile);                                 %# Load the data
[filePath,fileName,fileExt] = fileparts(dataFile);  %# Get the file name
dataSize = size(eval(fileName));                    %# Get the size of the data
disp(dataSize(1));  %# Display the rows
disp(dataSize(2));  %# Display the columns

You could also do this using the option to output the data from UIIMPORT as a structure where the data is stored in a field (with the file name as the default field name):

dataStruct = uiimport(dataFile);                    %# Put the data in a struct
[filePath,fileName,fileExt] = fileparts(dataFile);  %# Get the file name
dataSize = size(dataStruct.(fileName));             %# Get the size of the data
disp(dataSize(1));  %# Display the rows
disp(dataSize(2));  %# Display the columns

If you needed to pass the loaded data to another function, or use it in any other way, you can do the following:

some_other_fcn(eval(fileName));  %# When loaded with UIIMPORT to a variable
some_other_fcn(dataStruct.(fileName));  %# When loaded with UIIMPORT to a struct

这篇关于获取数据集matlab的大小,尺寸函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆