how to loop the following?

Okay I updated it with the photo of what I'm trying. Anyway help will be appreciated.
I'm trying to find force=mass*acceleration
mass is a 20 by 20 matrix
acceleration is a 20 by 1 column vector in the form [0,0,0,Xn,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]'
where Xn is a 1 by 2211 row vector.
Basically I'll be splitting the acceleration Xn term into its components and then add them up using the superposition theory.
I hope the photo helps clear things up.

回答 (1 件)

Image Analyst
Image Analyst 2017 年 2 月 11 日

0 投票

I believe this will do the strange thing you want to do:
x = randi(9, 1, 2211); % Whatever...
mass = ones(20);
accel = ones(size(mass, 1), 1);
accel(2) = sum(x, 2)
force = mass * accel

2 件のコメント

ramlal
ramlal 2017 年 2 月 11 日
hmmm but accel is really a column vector of zeros in my case with the 4 spot being X value in the 2211 column. So how would you phrase that? I'm not sure if you see what I'm saying
Image Analyst
Image Analyst 2017 年 2 月 11 日
I'm seeing your photo, where you showed various x elements but always in the second row, not in "the 4 spot" (meaning the 4th row I guess). If you want it in the 4th row instead, just do this:
accel(4) = sum(x, 2)

この質問は閉じられています。

タグ

質問済み:

2017 年 2 月 11 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by