How to create a matrix array with increments equation using vectorization?

23 次查看(过去 30 天)
I am trying to create a matrices array after calculating the area and volume of a system with increment equations. Basically the area and volume are changing from 1 to 10 seconds with 1 second increments. Then I have to create a matrix array showing the time with increments row as first column and corresponding calculated area and volume as the second and third column of the matrix using vectorization.
s=0.1;
y=pi;
x=1:1:5;
area=s.*sqrt(y.*x);
vol=s.*y*sqrt(y.*x);
B=[x area vol];
So basically my matrices should be 5x3. But I am confused as to how I can put the rows as increments, I am getting 1x15 matrices.

采纳的回答

KSSV
KSSV 2022-2-14
s=0.1;
y=pi;
x=[1:1:5]'; % transpose this
area=s.*sqrt(y.*x);
vol=s.*y*sqrt(y.*x);
B=[x area vol];
size(B)
ans = 1×2
5 3

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by