Extracting data from another column based on row conditions

2 次查看(过去 30 天)
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

采纳的回答

Joseph Cheng
Joseph Cheng 2022-10-26
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 个评论
Fe
Fe 2022-10-26
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)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 NaNs 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by