How to join datasets?

조회 수: 8 (최근 30일)
Xinyuan Wei
Xinyuan Wei 2016년 6월 18일
댓글: Muhammad Usman Saleem 2016년 6월 19일
I need to join some columns in the dataset attached below. When I joined the columns int_rate and id with the following code, it works.
TrainInputs = [TrainDataset.int_rate,TrainDataset.id]
But when I was trying to join the columns int_rate and sub_grade, it failed.
TrainInputs = [TrainDataset.int_rate,TrainDataset.sub_grade]
Error using horzcat
Dimensions of matrices being concatenated are not consistent.
Could you help me find out why and how should I do this? Thank you for your time.

답변 (1개)

Muhammad Usman Saleem
Muhammad Usman Saleem 2016년 6월 18일
check this in both columns vectors, these are not of same length.
TrainDataset.int_rate and TrainDataset.id are not of same length to concatenated. Always concatenate vector of same lengths
  댓글 수: 2
Xinyuan Wei
Xinyuan Wei 2016년 6월 19일
Thank you for your reply. But I still cannot understand.These three columns should all have 50 rows.
>> size(TrainDataset.id)
ans =
50 1
>> size(TrainDataset.int_rate)
ans =
50 1
>> size(TrainDataset.sub_grade)
ans =
50 1
Why matlab says they are not of the same length?
Muhammad Usman Saleem
Muhammad Usman Saleem 2016년 6월 19일
You can't horizontally concatenate scalars with matrices or column vector, hence the error.
Find out which variable is the culprit on why it's not scalar (or why you're using a non-scalar variable in your expression.
As i do not know how you three column vectors looks, The attached .m file also not opening. Please upload here its content

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by