Table printing null values until it satisfies the if condition

5 Ansichten (letzte 30 Tage)
Hello. I'm new to matlab. I'm trying to create a table based on an if condition. But the output table is printing null values until it reaches the row where it satifies the condition. So my table basically has a number of null rows before listing the actual rows I wanted. I think I must use an else block to skip if it doesn't meet my if condition but I don't know how to do that. I also came across something called logical indexing "output_table(condition, column) = value;" but I don't know how to use it. Please help. Thanks in advance.
if (type(j) == 4 && TypeProb (j) >= 25)
count = count+1;
box = i;
T1 = table(Var1,Var2,Var3,Var4,Var5,Var6,Var7,Var8,Var9,Var10,'VariableNames',Varname);

Akzeptierte Antwort

Ritish Sehgal
Ritish Sehgal am 27 Jan. 2023
I assume that you are looping over the if-else statements to create a table based on a condition.
You can create an else block and use the ‘continue’ command to skip the iteration in order to avoid writing null values to your table.
Here is the documentation for the ‘continue’ command.
Regarding logical indexing, it is a way to access or assign values to a matrix using a logical array with the same dimensions.
For example:
Suppose you have a matrix M and a logical array L of the same size, you can use the following syntax:
M(L) = value;
The above statement will assign the value to all the elements of M where the corresponding element in L is true.
Logical indexing can also be used to access elements of a matrix.
For example:
P = M(L);
The above statement would return a new matrix P that contains only the elements of M where the corresponding element in L is true.
You can refer to the documentation for examples of logical indexing.
Hope it helps!!

Weitere Antworten (0)


Mehr zu Matrix Indexing 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!

Translated by