I have a 3D matrix a
and a vector a1
. The size of a1
changes for each iteration. Now I want to input this vector into a certain position in a whose 2nd and 3rd column is defined. Something like this,
a(:,3,4)=a1;
But it gets the error "Assignment has more non-singleton rhs dimensions than non-singleton subscripts"
. How can i solve it?
If the size of a1
changes at each iteration, you will need to preallocate a
to the maximum size and use explicit subscripts for assignation
a = zeros(5,5,5)
a(1:length(a1),3,4)=a1;
Alternatively you can use a cell-array:
a{3,4} = a1
The cell array will be able to store vectors of different lengths.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.