Seperating strings and numbers using xlsread

I have some data in an excel sheet that each cell has words and a number. I wish to read in this sheet into two matrices of the same size, where one contains the words and the other contains the numbers. I can then perform the relevant functions on the numbers and get a script to display the corresponding text cell.
An example input xls sheet would be of the form of a 2x2 matrix:
adam (1.5) jordan (2.5)
james (2.9) chris (1.7)
And I would want this separated to:
adam jordan
james chris
and
1.5 2.5
2.9 1.7
any input would be helpful, thanks
-----------------edit------------------
I have now uploaded an xls file of an example dataset. The first column is the time (which i will retain when reading in) and the final column is irrelevant and can be ignored when reading in. My question is aimed towards the columns B:D in this file.
(the excel file is xls to upload, but it will be xlsx when im using matlab.)

4 件のコメント

Adam Cook
Adam Cook 2017 年 7 月 13 日
Appreciate the edit dpb, how do I do that myself in future?
KSSV
KSSV 2017 年 7 月 13 日
How the data is in excel file?
Adam Cook
Adam Cook 2017 年 7 月 13 日
just added the data KSSV, thanks Jan.

サインインしてコメントする。

 採用された回答

per isakson
per isakson 2017 年 7 月 13 日

1 投票

Loops are allowed
>> [ str, num ] = cssm0();
>> whos str num
Name Size Bytes Class Attributes
num 33x3 792 double
str 33x3 12928 cell
where
function [ str, num ] = cssm0()
[~,txt] = xlsread('test.xls');
len = size(txt,1);
str = cell( len, 3 );
num = nan( len, 3 );
for jj = 1 : len
for ii = 1 : 3
if not( isempty( txt{jj,ii} ) )
cac = textscan( txt{jj,ii}, '%s%f', 'Whitespace',')', 'Delimiter','(' ) ;
str{jj,ii} = strtrim(cac{1}{1});
num(jj,ii) = cac{2};
else
str{jj,ii} = '';
num(jj,ii) = nan;
end
end
end
end

1 件のコメント

Adam Cook
Adam Cook 2017 年 7 月 13 日
Thanks Per! Does exactly what I wanted! Now to deconstruct it and teach myself the inner workings of this beauty.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

質問済み:

2017 年 7 月 12 日

コメント済み:

2017 年 7 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by