Effacer les filtres
Effacer les filtres

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

9 vues (au cours des 30 derniers jours)
Homayoon
Homayoon le 19 Fév 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

Réponses (1)

Walter Roberson
Walter Roberson le 19 Fév 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'

Community Treasure Hunt

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

Start Hunting!

Translated by