Assignment has more non-singleton rhs dimensions than non-singleton subscripts help
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
James Tursa
am 9 Apr. 2015
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?
Akzeptierte Antwort
Stephen23
am 9 Apr. 2015
Bearbeitet: Stephen23
am 9 Apr. 2015
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
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!