Unable to create an array from a table

若如初见. 提交于 2019-12-11 07:34:31

问题


I'm trying to load an external CSV file using MATLAB.

I managed to download it using webread, but I only need a subset of the columns.

I tried

Tb = webread('https://datahub.io/machine-learning/iris/r/iris.csv');     
X = [sepallength sepalwidth petallength petalwidth];

But I cannot form X this way because the names are not recognized. How can I create X correctly?


回答1:


The line

Tb = webread('https://datahub.io/machine-learning/iris/r/iris.csv');

Produces a table object with column names you later try to access as if they were workspace variables - which they aren't. Instead, you should modify your code to use:

X = [Tb.sepallength Tb.sepalwidth Tb.petallength Tb.petalwidth];


来源:https://stackoverflow.com/questions/56890311/unable-to-create-an-array-from-a-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!