import an excel file containing both numbers and strings into a matrix
4 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Walter Roberson
on 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'
0 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!