Extracting data from another column based on row conditions
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
Joseph Cheng
am 26 Okt. 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;
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu NaNs finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!