Assignment has more non-singleton rhs dimensions than non-singleton subscripts help
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi, I am trying to make something like a table so for every iteration (1:200) a new column is added in 'list_val' but with a variable number of elements in each column. I get the error on the 'list_val(:,it_3)=val_set(o_ue);' line. The following code is embedded in a for loop wiith iteration (it_3=) 1:200. 'list_val', 'val_set' and 'o_ue' are pre-defined and in the first iteration where the error appears the rhs has 3 values.
if length(o_ue)>0
list_val(:,it_3)=val_set(o_ue);
end
댓글 수: 2
James Tursa
2015년 4월 9일
What do you mean by "... variable number of elements in each column ..."? What are the dimensions of list_val to begin with? What is the size of the val_set(o_ue) result? Are you trying to stuff a variable number of elements in a brand new column with 0 padding on the end?
채택된 답변
Stephen23
2015년 4월 9일
편집: Stephen23
2015년 4월 9일
The trick to including different-length columns into a matrix is to define the subscript indexing, and not just using the colon operator to allocate the whole column:
dat = {[1,2,3],4,[5,6,7,8,9],[]};
out = [];
for k = numel(dat):-1:1
vec = dat{k};
out(1:numel(vec),k) = vec;
end
produces this matrix:
>> out
out =
1 4 5 0
2 0 6 0
3 0 7 0
0 0 8 0
0 0 9 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!