matlab read data,科学网—Matlab Read Excel Data with String and Numeral - 李旭的博文

Sometimes, Data was saved as Excel file format. And, it often contains strings and numerals in a column, we all know that Matlab reads the data as a m-by-n Cell Arrary. It is difficult to get and set all together, the following is an example to convert numerals to string in Cell Arrary.

Main Program:

clear;

clc;

% Read Two.xlsx For Values

% Num is an Arrary in Double, all numeralsare in it, and non-numerals all are filled in NaN.

[Num, ~, Values2]=xlsread('Two.xlsx','A1:BXQ1356');

% Convert Values to CellStr Every Column

for ii=1:size(Num, 2)

Values2(:, ii)=ReAssign(Num(:, ii), Values2(:, ii));

fprintf('%d Col done!n', ii);

end

clear Num

Function ReAssign:

% Created by LI Xu

% 21 November, 2013

% Version 1.0

% Description

% Data from Excel Tables can be assigned toanother file

% in order.

function ColCells=ReAssign(ColNum, ColRaw)

num=ColNum;

raw=ColRaw;

% Index of Txt

Num=num2str(num);

Num=cellstr(Num);

Num=strfind(Num, 'NaN');

% Whether Empty Set

Index_Txt=logical(size(Num));

for ii=1:length(Num)

Index_Txt(ii)=~isempty(Num{ii});

end

Index_Txt=Index_Txt';

% Index of Number

Index_Num=~Index_Txt;

raw(Index_Num)=cellstr(num2str(num(Index_Num)));

ColCells=raw;

转载本文请联系原作者获取授权,同时请注明本文来自李旭科学网博客。

链接地址:http://blog.sciencenet.cn/blog-1148346-743627.html

上一篇:Matlab problem in Saving the Figure with GEOTIFF layer

下一篇:Introductions for ENVI Compiled Procedures?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值