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

조회 수: 10 (최근 30일)
Homayoon
Homayoon 2016년 2월 19일
답변: Walter Roberson 2016년 2월 19일
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에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by