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

1 回表示 (過去 30 日間)
Benjamin Horsley
Benjamin Horsley 2021 年 2 月 18 日
コメント済み: Benjamin Horsley 2021 年 2 月 18 日
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 Center および File ExchangeProgramming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by