import an excel file containing both numbers and strings into a matrix

4 次查看(过去 30 天)
Hello All--
I do have an excel file whose first column contains numbers and the second column has letters. Something similar to the matrix below:
1 a
2 b
3 c
Once I am using xlsread function, only the first column is imported. And once I am using xlsread function with the second output as [num,txt] = xlsread ('FILE.xlsx'), the columns are imported separately.
What I need is to import the excel file in the matrix format as follows:
B= [1 a
2 b
3 c]
What should I do?
Then I would like manipulate the imported matrix. for example
for i=1:3
if B(i,2) == 'a'
do something
end
end
Any idea how may I proceed?
Thanks

回答(1 个)

Walter Roberson
Walter Roberson 2016-2-19
[~, ~, raw] = xlsread ('FILE.xlsx');
It is not possible to get a matrix like
B= [1 a
2 b
3 c]
in MATLAB. In MATLAB, it is not possible to combine text and numeric values in the same matrix. The closest possible is a cell array, which would look like
>> B = {1, 'a'; 2, 'b'; 3, 'c'}
B =
[1] 'a'
[2] 'b'
[3] 'c'

类别

Help CenterFile Exchange 中查找有关 Data Import from MATLAB 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by