Using data from table in calculations

21 visualizaciones (últimos 30 días)
Stephen Fleming
Stephen Fleming el 2 de Feb. de 2021
Comentada: Stephen Fleming el 2 de Feb. de 2021
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:
X=(TableName.ColumnName1);
Y=(TableName.ColumnName2);
Z=(TableName.ColumnName3);
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
Thanks!
  2 comentarios
Mario Malic
Mario Malic el 2 de Feb. de 2021
Hello,
Here's an example
load patients.mat
t = table(Height,Weight)
t.Height
This will return a vector of numeric values, just like your X variable. How are you using your X in the code? Do you have another vector that you want it to multiply with, or you have a scalar that you're multiplying it with?
Stephen Fleming
Stephen Fleming el 2 de Feb. de 2021
Hi, thanks for replying!
So I am combining the value with another vector. Each of my values has a corresponding angle in the same row in the tabel. I am then combining these to get them into cartesian form (splitting real and imaginary parts) to be able to perform calculations with them.
Thanks

Iniciar sesión para comentar.

Respuestas (1)

Adam Danz
Adam Danz el 2 de Feb. de 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));
end

Categorías

Más información sobre Logical en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by