How to make equally spaced symbols on a line plot

I have a line plot (created from an array with many many points) and I want to use symbols rather than colours to indicate the different data. Does anyone know how to do this?
I know you can't simply add 'o' at the end because this gives error message 'The end operator must be used within an array index expression'
Cheers!

2 comentarios

Voss
Voss el 24 de Jul. de 2023
Can you post the plotting code you have so far?
Em
Em el 24 de Jul. de 2023
The below line works just fine
plot(var1(end-1000:end,1)*10^-6, var1(end-1000:end,3)*10^9)
I want to plot it with symbols e.g.
plot(var1(end-1000:end,1)*10^-6, var1(end-1000:end,3)*10^9, 'o')

Iniciar sesión para comentar.

Respuestas (1)

Do you want something like this?
x = 1:100;
y = sin(x/10);
plot(x,y) % the whole line
hold on
plot(x(1:10:end),y(1:10:end),'bo') % markers every so often

4 comentarios

Em
Em el 24 de Jul. de 2023
Editada: Em el 24 de Jul. de 2023
Thank you for this! It looks like it's close
Unfortunately, I'm now getting this error message:
Data must be a single input of y-values or one or more pairs of x- and y-values.
when I run
plot(s9a(end-1000:end,1)*10^-6, s9a(end-1000:end,3)*10^9,'Color',c(5,:), 'LineWidth',1)
hold on
plot(s9a(end-1000:10:end,1)*10^-6, s9a(end-1000:10:end,3)*10^9,'Color',c(5,:), 'o')
That indicates to me that vacuum1a is not a variable that you're trying to index into but is more likely a function that you're trying to call. I'm guessing specifying the symbol is not the cause of the error, but that you've cleared or overwritten the variable that your first call used. As a simpler example below, note that there is no variable named sin so MATLAB is trying to call the sin function. But you can't use end like that in a function call.
y = sin(end-1:end)
The end operator must be used within an array index expression.
To check, run this command immediately before your plot call:
which -all vacuum1a
Em
Em el 24 de Jul. de 2023
You're right, I didn't have the right .mat file loaded! Sorry to you or to anyone else who is viewing this - I edited my reply before I saw that you had replied.
I'm getting another error message when I include the ':10:' part of my code. Do you have any idea why this might be?
Cheers.
Voss
Voss el 24 de Jul. de 2023
Editada: Voss el 24 de Jul. de 2023
Instead of this:
plot(s9a(end-1000:10:end,1)*10^-6, s9a(end-1000:10:end,3)*10^9,'Color',c(5,:), 'o')
Do this:
plot(s9a(end-1000:10:end,1)*10^-6, s9a(end-1000:10:end,3)*10^9,'o','Color',c(5,:))
Property/Value pairs, like 'Color',c(5,:), must come at the end of the list of arguments to plot.

Iniciar sesión para comentar.

Categorías

Productos

Versión

R2021b

Preguntada:

Em
el 24 de Jul. de 2023

Editada:

el 24 de Jul. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by