필터 지우기
필터 지우기

Need to combine doubles with different sizes

조회 수: 7 (최근 30일)
jgillis16
jgillis16 2016년 1월 19일
댓글: jgillis16 2016년 1월 20일
I need to combine a set of doubles into one double matrix. My problem is that they are all different sizes. How would I go about doing this?
  댓글 수: 3
Walter Roberson
Walter Roberson 2016년 1월 19일
Are you trying to put each member into a row (or column) with them starting as different lengths, and you want to end up with a rectangular matrix that has NaN in each location where there was no value?
jgillis16
jgillis16 2016년 1월 19일
Walter, yes you're on the right track. I have several different doubles that I need to combine but they all have varying lengths. The problem I'm facing is that say I have an 'x' double. This 'x' double is associated with another set of 'y' double that is the same length as the 'x' double because they come from the same source of data. But, I have several sets of these pairs of 'x' and 'y' doubles, but they are all different lengths. How would I make these separate 'x' and 'y' doubles the same length as each other?

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

채택된 답변

Walter Roberson
Walter Roberson 2016년 1월 19일
If packing by columns then
YourXArray(1:length(x), Column_Number) = x;
If the x is larger then the current maximum number of rows then the array will be automatically grown and padded with 0s. If you want a different pad value then you need to indicate to us what padding you want.
  댓글 수: 3
Walter Roberson
Walter Roberson 2016년 1월 20일
Then perhaps you should be padding with something else like -inf or nan
Lx = length(this_x);
if Lx > size(YourXArray,1)
YourXArray( size(YourXArray,1)+1 : Lx, :) = PadValue;
end
YourXArray(1:Lx, ColumnNumber) = x;
jgillis16
jgillis16 2016년 1월 20일
what does 'this_x', and 'x' refer to? thanks!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by