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

1 回表示 (過去 30 日間)
ajk1
ajk1 2015 年 4 月 9 日
コメント済み: ajk1 2015 年 4 月 9 日
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 Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by