Why am I receiving an error message in an array calculation?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Benjamin Horsley
am 18 Feb. 2021
Kommentiert: Benjamin Horsley
am 18 Feb. 2021
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.
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Types finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!