Assignment has more non-singleton rhs dimensions than non-singleton subscripts help

4 次查看(过去 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
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?
ajk1
ajk1 2015-4-9
Hi there, the number of results of val_set(o_ue) is different after each iteration. After the first iteration the size is 3x1 and in the second iteration it will be a different size (nx1 result where n is a integer). I want these values to be stored in list_val, each succeeding iteration being stored in a new column. I haven't assigned a dimension to list_val because I am trying to make the dimensions to be dynamic. I'm trying to store a variable number of elements in a new column with 0 padding. Thanks.

请先登录,再进行评论。

采纳的回答

Stephen23
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 CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by