带有“。”的值不会从Excel文件导入

我有一个看起来像这样的excel文件:

Excel中的文件

每次我的文件包含这样一行: 2 1.258 4.587 6.325 ,我的代码不读取数字. 或者,对于给定的行,只有2被导入。

这是我的代码(运行良好,但不是当我的文件包含十进制值):

 Xtrain1 = xlsread('mma_kag\train1.xlsx','B:F'); 

错误是:

数据点的维度必须大于0

这意味着它不会读取文件,我已经检查过它。 这是[] 。 如何解决这个问题?

这里是excel文件的链接

你的单元格中的数字被认为是文本,因此错误。 这与数字不是整数无关。 有两种方法可以解决这个错误。

Excel方法

  • select所有单元格(按Ctrl + A )。
  • 然后点击 这个 。 这将打开一个下拉菜单。
  • 现在select转换为数字
  • 保存excel文件( Ctrl + S )。 (如果您需要,请保留前一份的副本)

excel方法

有关详细信息,请阅读以下主题:
通过应用数字格式修复文本格式的数字


MATLAB方法:
使用xlsread的第三个输出并将文本转换为如下所示的双xlsread

 [~, ~, Xtrain1] = xlsread('mma_kag\train1.xlsx','B:F'); Xtrain1 = str2double(Xtrain1); %Converting the strings in the cell to double 

编辑:如果你的文件有任意分散的文本数字(就像你上传的新文件一样),你需要xlsread第一个和第三个输出。 类似以下的事情可以做:

 [tmp,~, Xtrain1] = xlsread('train1.xlsx'); %Select the range as per your need if necessary Xtrain1 = str2double(Xtrain1); %Above line will convert the text into numbers and the numbers will be converted to NaNs Xtrain1(isnan(Xtrain1))=tmp(~isnan(tmp)); %Above line retrieves the numbers from `tmp` & stores them in `Xtrain1`