How to plot it?
Mostrar comentarios más antiguos
Dear All,
We have
a=1,2,3,4,5; (in a column 1)
b=-1000,10,0,20,-20; (in a column 2)
b_filtered=b(:,2)>=0;
plot (a,b_filtered);
How to plot these two values that after filtered they have two different dimensions?
Best,
Respuesta aceptada
Más respuestas (3)
Mathieu NOE
el 13 de Jul. de 2022
hello
simply replace the negative values of b by NaN so the vector size remains the same
a=[1;2;3;4;5];
b= [-10;10;0;20;-20];
b_filtered=b;
b_filtered(b<0) = NaN;
plot (a,b,a,b_filtered,'dr');
3 comentarios
Ara
el 13 de Jul. de 2022
Mathieu NOE
el 13 de Jul. de 2022
hello
both answers are correct and will display the exact same plot
I wanted to have both b and b_filtered the same size as a , because it seemed to me that you wanted it this way.
the other options as suggested by @Chunru works also , and if you want to have both b and b_filtered displayed , you can slightly modify his code :
it's up to you to pick the one you prefer
a = [1,2,3,4,5];
b = [-10,10,0,20,-20];
idx = b>=0;
plot(a,b,a(idx), b(idx), 'or');

Ara
el 16 de Jul. de 2022
It is my understanding that you are trying to plot a and b_filtered. I believe b_filtered is supposed to contain the non-negative elements of b, please correct me if I'm wrong on this, I did not understand what exactly is (b(:,2)>=0) supposed to do? If I'm not wrong, we can retain the elements of a at the indices where b is not negative and plot a and b accordingly.
a=[1;2;3;4;5];
b= [-10;10;0;20;-20];
b(b<0)=NaN;
a(b<0)=NaN;
b_filtered=b;
p=plot (a,b_filtered,"red");
Ara
el 13 de Jul. de 2022
0 votos
3 comentarios
Ruchika P Barman
el 13 de Jul. de 2022
Editada: Ruchika P Barman
el 13 de Jul. de 2022
Do you mean 'b' by 'second column of my data' or second column of 'b' which is a single element i.e 10? If it is the former, then the output from both the answers are correct.
Please let me know if I can help you further, thank you.
Ara
el 14 de Jul. de 2022
Categorías
Más información sobre Annotations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

