Adding values to 3d matrix
Afficher commentaires plus anciens
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
Réponse acceptée
Plus de réponses (1)
Roger Stafford
le 24 Déc 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
Catégories
En savoir plus sur Discontinuities dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!