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
0 个评论
采纳的回答
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;
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 NaNs 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!