Extracting data from another column based on row conditions

8 visualizaciones (últimos 30 días)
Fe
Fe el 26 de Oct. de 2022
Comentada: Fe el 26 de Oct. de 2022
Hello,
I get an error to extract data from column B as the resulting condition on the left would result to less rows than table B
code:
%create a new column X
Table.X(Table.C > 0 & isnan(Table.E)) = Table.B
Error: unable to perform assignment because the size of left side is 420 by 1 and right side is 497 by 1.
Thanks in advance for any tips you can give me.
BR,
Fe

Respuesta aceptada

Joseph Cheng
Joseph Cheng el 26 de Oct. de 2022
So if we create a simple example
C = [-6:6]';E=C;E(1:5)=nan;B=2*C;Table = table(C,E,B)
Table.X(Table.C > 0 & isnan(Table.E)) = Table.B(Table.C > 0 & isnan(Table.E))
C E B X
__ ___ ___ __
-6 -6 -12 0
-5 -5 -10 0
-4 -4 -8 0
-3 -3 -6 0
-2 -2 -4 0
-1 NaN -2 0
0 NaN 0 0
1 NaN 2 2
2 NaN 4 4
3 NaN 6 6
4 NaN 8 8
5 NaN 10 10
6 NaN 12 12
so what is happening in your error is that there is no "filter" for the Table.B but the whole column trying to be fitted into a smaller condition where [Table.C > 0 & isnan(Table.E)]==1;
  1 comentario
Fe
Fe el 26 de Oct. de 2022
Hey,
Thanks for thr explanation. Helpful ☺ I did this and works perfectly 😆
Table.X = Table.B Table.X(conditions) = „“
As I needed only entries over there when conditions are not met (mistake in original post)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by