Adding values to a table from an if statement
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I'm performing a sequential Gaussian analysis and am trying to populate a table using an if statement. I keep getting an error saying that dot indexing is not supported for varialbes of this type for this section of code. Basically, I have preset a table with zeros, and then the code checks against another table X if the value is smaller or larger than the min and max defined. I want the code to assess the if statement and then populate the table Z with 0 or 1 in the column specified. Thanks!
X = [157.5:315:31342.5];
Z = zeros(100,11);
maxnum = max(T.Var2);
minnum = min(T.Var2);
for a = 1:100
if X{a,1} > minnum & X{a,1} < maxnum
Z.Var1{a} = 1;
else
Z.Var1{a} = 0;
end
end
0 comentarios
Respuestas (2)
Walter Roberson
el 16 de Jul. de 2021
X = (157.5:315:31342.5).';
Z = table();
maxnum = max(T.Var2);
minnum = min(T.Var2);
Z.Var1 = minnum < X & X < maxnum;
0 comentarios
Cris LaPierre
el 16 de Jul. de 2021
Z is not a table. It is a 100x11 matrix of zeros. Therefore, you would use normal indexing (row, column) to assign values to it.
Also, you do not need the for loop. Create a logical array instead, and assign that to the desired column (see ch 12 of MATLAB Onramp).
I've made your matrix smaller for demontration purposes.
X = 1:10;
Z = zeros(10,2);
maxnum = 8;
minnum = 5;
V = X>minnum & X<maxnum
Z(:,1) = V
1 comentario
Peter Perkins
el 27 de Jul. de 2021
Also, X is not a cell array, so X{a,1} wasn't going to work, you needed X(a,1). In any case, Wlater's non-loop sol'n is the way to go.
Ver también
Categorías
Más información sobre Graphics Object Programming en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!