Adding values to 3d matrix
Show older comments
Dear all,
I have an emtpy 16x16x16 matrix, which i'm trying to update on the following locations:
x = [1,16,16]
y = [1,8,16]
z = [2,4,16]
The values are:
values =[1, 2, 1]
I have tried to do this as such:
matrix(x,y,z) = values
However, I get the following error:
Assignment has fewer non-singleton rhs dimensions than non-singleton subscripts
What am I missing here?
Any help would be greatly appreciated
Cheers
Accepted Answer
More Answers (1)
Roger Stafford
on 24 Dec 2012
There is a way around for-loops using 'sub2ind'.
M = zeros(16,16,16);
M(sub2ind(size(M),x,y,z)) = values;
Roger Stafford
Categories
Find more on Discontinuities in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!