# I want my solution as a Vector

2 vues (au cours des 30 derniers jours)
Patrick Brandt le 23 Avr 2021
Commenté : Patrick Brandt le 23 Avr 2021
Hi guys,
I wrote the following code to calculate the center of mass in the in the X direction of every single layer of a 58x22x122 Matrix. The solutions are correct, but I want the answers in form of a 1x122 Vector, do you have any idea how to realize it?
R=0;
for z=1:122
for x=1:22
for y=1:58
R=R+A(y,x,z)*x;
end
end
Q=A(:,:,z);
N=sum(Q,[1,2]);
X=R/N
R=0;
end
I hope anyone can help me.
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponse acceptée

Daniel Pollard le 23 Avr 2021
Does this work?
X(z) = R/N;
X = R/N
##### 1 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
Patrick Brandt le 23 Avr 2021
Yeah thank You!!!

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by