Using data from table in calculations
20 views (last 30 days)
I have recently started using MATLAB and have a basic understanding of it. I have a table with 99000 rows (these rows are values at particular times) in it and want to perform the same calculation on each row giving an output, then moving to the next row, perform the calculation and so on.
I can perform the calculation by manually entering the numbers but want my script to be able to get the values itself. I have tried calling the input columns like:
and they do give out an array. But then I get an error when it tries to put X, Y & Z through the calculation. Is there a certain loop I need to do to go through this in iterations?
(p.s, I have searched online and on the Using Tables section of MATLAB help but to no avail.)
Any help is appreciated
Adam Danz on 2 Feb 2021
Have you tried a simple loop like this?
% Function returns a scalar value and stores it in a vector.
% Function contains 3 inputs.
out = zeros(1, height(TableName)); % preallocate; assuming a vector
for i = 1:height(TableName)
out(i) = fun(TableName.Col1(i), TableName.Col2(i), TableName.Col3(i));