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

3 Ansichten (letzte 30 Tage)
Homayoon
Homayoon am 19 Feb. 2016
Beantwortet: Walter Roberson am 19 Feb. 2016
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

Antworten (1)

Walter Roberson
Walter Roberson am 19 Feb. 2016
[~, ~, 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'

Kategorien

Mehr zu Data Import from MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by