creating an array from an object

1 回表示 (過去 30 日間)
matthew arnott
matthew arnott 2013 年 4 月 17 日
Hi,
I have an object which comes from a database and is in the following format
cats 100 200 300 100 dogs 50 100 110 80 mice 80 30 40 200
I am using cell2mat to create matrices from the object for coloumns 2 - 5 - however you cannot mix strings and numbers and infact you cant even get a matrix of coloumn 1 ie the strings cats, dogs, mice. I need to create a separate matrix - or I believe it will be called an array in this instance that returns underneath each other all the strings from coloumn 1.
Many thanks

採用された回答

matthew arnott
matthew arnott 2013 年 4 月 18 日
Not sure if its the correct thing to do but in my example the "num2cell" function has worked even though I am dealing with strings and not numbers. So I used
s = num2cell(Objectname(1)) s2 = s{1,1} s3 = s2{1}

その他の回答 (2 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 4 月 17 日
s={'cats' 100 200 300 100 'dogs' 50 100 110 80 'mice' 80 30 40 200}
out=s(cellfun(@isstr,s))
  1 件のコメント
matthew arnott
matthew arnott 2013 年 4 月 17 日
Many thanks for the help however I am starting from an OBJECT not a list so the cellfun function returns an empty matrix - not being a guru, unforunatley I cannot explain it any better. The object is the return of a query into a database so its a database object if you like. the cell2mat function is able to return matrices of the numeric numbers but not an array or matrix of the words.

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


matthew arnott
matthew arnott 2013 年 4 月 17 日
Appreciate the help. However my starting point is an object not a list - so the cellfun function returns an empty matrix

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by