How do you get matlab to import/read a column vector of strings or characters??

How do you get matlab to import a column vector of strings or characters??
[zone]=xlsread('Tox_model.xlsx',2,"E5:E10");
E5-E10 reads like this in excel:
s1
s2
s3
s2
s3
s1
In reality the colum vector is very long (1000s) and not just a (1:5) vector ...
The variable is empty when I run the code. Why???

 Akzeptierte Antwort

Did you try reading into a cell array?
zone=readcell('Tox_model.xlsx');

5 Kommentare

mmmm. matlab doesn't like that.
>> testwatercontam
Error using readcell (line 139)
Expected a string scalar or character vector for the parameter name.
Error in testwatercontam (line 23)
[zone]=readcell('Tox_model.xlsx',2,"E5:E102");
It would help if you attached your spreadsheet.
Thank you!! I added the .m file along with the excel doc it calls. I added a note in the .m file to indicate where I'm going astray. I've got it now so that I loaded the excel character column into matlab, but it comes in as a cell array. I saw in one of the other older posts to conver it to a cell array...but then it goes from a 98x1 cell array to a 98x2 character array....I just want it as a normal 98x1 vector and can't seem to quite get it there. So if in the if/else series, I say if you see s1 do this if not then do something else...for a rough example. In any case I really apprecaite your help!
m=readmatrix('Tox_model.xlsx','Sheet','PWS PFHxS Conc','Range','D5:L102');%much easier to read into a matrix and use indexing
a=readcell('Tox_model.xlsx','Sheet','Participants'' water intake ','Range','E5:E102');
k={'s1','s2','s3','w1','w23','w4','w5','f1','f2','sh'}
for n=1:length(a)
WatCon(n)=m(n,ismember(k,a(n)));%there are several 's0','s5','s4' listed in array that do not correspond
end

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Gefragt:

am 27 Jan. 2021

Kommentiert:

am 28 Jan. 2021

Community Treasure Hunt

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

Start Hunting!

Translated by