Why am I receiving an error message in an array calculation?

1 次查看(过去 30 天)
I'm having some difficulty performing an array calculation. I would like to fill the contents of column 3 based on a specific formula using the contents of columns 1 and 2. I have some example code below.
% Example data.
column1data = [231.3 228.8 237.5 222.5]';
column2data = [107.5 121.3 108.8 111.3]';
% I want to create an addtional 3 columns so I end up with a 4 x 5 array.
% I first create a vector that is the same length as vectors 1 and 2.
lendata = length(column1data);
% I then create three additional vectors (columns) of zeros and join all together.
column3 = zeros(1, lendata)';
column4 = zeros(1, lendata)';
column5 = zeros(1, lendata)';
array = [column1data column2data column3 column4 column5];
Once I've created the array, I want to use the below formula to return 4 values in column 3.
array(:, 3) = (81*9.81)*(3.14/2)*((array(:, 2)/array(:, 1)) + 1);
However, I get an error message returned. Can someone please advise what I'm missing?
Thank you.

采纳的回答

Walter Roberson
Walter Roberson 2021-2-18
use ./ not /

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Operators and Elementary Operations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by