Extracting data from another column based on row conditions

8 vues (au cours des 30 derniers jours)
Fe
Fe le 26 Oct 2022
Commenté : Fe le 26 Oct 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

Réponse acceptée

Joseph Cheng
Joseph Cheng le 26 Oct 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 commentaire
Fe
Fe le 26 Oct 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)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by