Extract the value according to the number of rows

조회 수: 2 (최근 30일)
Siti Suhaila
Siti Suhaila 2017년 8월 10일
댓글: Walter Roberson 2017년 8월 14일
Hello everyone, I need to extract or reshape the array value (cixd) so that the number of value is based on the num of rows(picture A) and store at the next column. Here shows some illustration. The extraction continues until it goes to 10895 that follows the value of picture A. I tried used reshape but the error says I cannot change the num of the element.
combineResultDisengged=vertcat(FeaturesDis{:});
s{k,:}=size(FeaturesDis{k},1) %extract value rows only
end
[cidxD,cmeansE] = kmeans(combineResultDisengged,500);
R=reshape(cidxD,s{:,1})
end
  댓글 수: 6
Siti Suhaila
Siti Suhaila 2017년 8월 11일
The second case, 197 should be the next 197 elements after the 185 already "used up".
Siti Suhaila
Siti Suhaila 2017년 8월 11일
R = reshape(cidxE, 10, []);%extract each 10 rows
However, I don't want to restrict it to 10 rows only. I need to extract the rows based on the value of picture A and continues to the next column for the second rows (197) and so on. Did I clearly explain it?

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

답변 (1개)

Walter Roberson
Walter Roberson 2017년 8월 11일
Let the size information be in A. Let the array to be split be B.
total_requested = sum(A);
if total_requested > length(B)
error('A requests more entries than there are in B');
end
B_split = mat2cell(B(1:total_requested), A, 1);
Now B_split is a cell array with column vectors of varying lengths. However you cannot arrange them beside each other until you define how to handle the "holes"
  댓글 수: 4
Siti Suhaila
Siti Suhaila 2017년 8월 14일
I managed to get the correct value of the first rows and the matrix display the number accordingly, however, it started with the first and duplicate it to the next column.
Walter Roberson
Walter Roberson 2017년 8월 14일
Are you referring to the fact that M_extract{1,1}(185) is 197, and 197 also happens to be the second length to use according to picture A ?
We do not have your data to test with.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by