How to select which plots to print (or not) out of a cell matrix?

4 visualizaciones (últimos 30 días)
So I have a cell matrix of 21x14, each cell contains an array with 2 columns of data (x and y for exmaple), I get the average of these values and get just 1 graph out of each cell. The problem is that some of the cells are empty (just zero values), and this depends on my data, so it changes everytime I add new (or remove) data. I don't know how to tell Matlab to print only the plots of nonzero data, other wise I end up with 294 graphs after almost 2 hours of processing time from which a lot are just empty graphs.
Im using a for loop to get the averages and plots of each cell.

Respuesta aceptada

Abhinav Gupta
Abhinav Gupta el 13 de Jun. de 2021
You can use the built-in method all() of matlab to check, if all array elements are nonzero or not. As every element of your cell matrix is a matrix of say n rows and 2 columns, you could use all() method before plotting the graph for each cell.For eg.
>> B = [0 0; 0 0; 0 0; 0 0]
B =
0 0
0 0
0 0
0 0
>> all(B(:)==0)
ans =
logical
1
>> A = [1 0; 0 0; 1 2; 0 0]
A =
1 0
0 0
1 2
0 0
>> all(A(:)==0)
ans =
logical
0
Plot the graph only when you get 0 as the output.
  1 comentario
Dandro18048
Dandro18048 el 14 de Jun. de 2021
Editada: Dandro18048 el 14 de Jun. de 2021
Thank you for your answer! Unfortunately when I try to use the function all for the cells I get the following error: Undefined fucntion 'all' for input argumetns of type 'cell'.
I managed to solve the problem using an if statement and an apprach kinda like yours with the help of the function cell2mat. So will accept the answer for being the only useful answer I got!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Specifying Target for Graphics Output en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by