Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 将xls文件导入全字符串单元格数组_Matlab_Casting_String Formatting_Cell Formatting_Xlsread - Fatal编程技术网

Matlab 将xls文件导入全字符串单元格数组

Matlab 将xls文件导入全字符串单元格数组,matlab,casting,string-formatting,cell-formatting,xlsread,Matlab,Casting,String Formatting,Cell Formatting,Xlsread,我正在尝试导入一个包含数字和字符串数据的xls文件。现在我希望输出是一个仅由字符串组成的单元格-数组。 我曾经 读取文件。现在我正在寻找一种方法,将raw的所有单元格转换为字符串。事实上,我使用 raw=cellfun(@convertmat2char,raw); function charData = convertmat2char(data) if isnumeric(data) charData={num2str(data)}; else charData={data};

我正在尝试导入一个包含数字和字符串数据的xls文件。现在我希望输出是一个仅由字符串组成的
单元格
-数组。 我曾经

读取文件。现在我正在寻找一种方法,将
raw
的所有单元格转换为
字符串。事实上,我使用

raw=cellfun(@convertmat2char,raw);

function charData = convertmat2char(data)
if isnumeric(data)
    charData={num2str(data)};
else
    charData={data};
end
end

但这是可笑的缓慢。我想这可以通过一个非常简单的矩阵运算来完成,但我似乎不知道怎么做。

与其检查它是否是数字,不如直接在所有的矩阵上使用
像这样使用

raw = cellfun(@num2str, raw, 'UniformOutput', 0);
多长时间

nonNaNnumeric = numeric(~isnan(numeric));
num2str(nonNaNnumeric)

拿走?这是将数字转换为字符串的时间。如果速度不够快,您应该尝试更快的printf。如果这速度太慢,那么首先需要将xls中的数据作为字符串导入,以避免这种转换,我不知道如何进行转换,也不知道是否可能进行转换。

我必须承认,这比我之前做的要优雅得多,但它似乎没有更快。正如我在问题中所说,如果可能的话,我正在寻找一个快速的解决方案。无论如何谢谢你的帮助,如果没有更好的解决办法,我会接受你的回答。@Max我认为那是不可能的。虽然,如果您使用的是Windows操作系统和Excel for Windows®,您可以通过使用
xlsread
@Sardar\u Usama节省一些时间。您是指他已经用来生成单元格数组的
xlsread
?我刚刚对您的解决方案与我的解决方案以及我的文件进行了计时(它们非常大)你的答案是160秒,我的答案是170秒,这没什么大不了的。“使用
xlsread
”是什么意思?我正在使用
xlsread
@excaza我所说的是在基本导入模式下使用
xlsread
。我将在接下来的几天内给你反馈。因为我刚离开工作场所,现在无法访问数据。
nonNaNnumeric = numeric(~isnan(numeric));
num2str(nonNaNnumeric)