# How do I use xline() to plot values calculated in a for loop?

7 Ansichten (letzte 30 Tage)
Michael Boyte am 19 Apr. 2023
Kommentiert: Les Beckham am 19 Apr. 2023
I am trying to plot a set of vertical lines where each line's x-value is i/d where i iterates from 1 to d and d is a denominator that is calculated based on user input, beta. My code looks like this:
[n, d] = numden(sym(beta));
for i = 1:d
x(i) = i/d;
end
xline([x])
But I get this error:
Error using matlab.graphics.internal.xyzline
Value must be one of the following: 'numeric' | 'datetime' | 'categorical' | 'duration'
Error in xline (line 35)
h = matlab.graphics.internal.xyzline('x', args);
If beta = 0.75, then x = [1/4, 1/2, 3/4, 1], which is exactly what I want. I have noticed that if I manually set x to be [1/4, 1/2, 3/4, 1], then it works, but if i use the for loop to calculate x, it does not work despite x being, as far as I can tell, identical. Is what I'm wanting to do possible?
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Les Beckham am 19 Apr. 2023
Your x is going to be symbolic based on the code you posted (you can verify this by using the whos in the Command Window or by looking in the Workspace window). If you must calculate x symbolicly, you can convert it to numeric using the double command.
##### 2 Kommentare1 älteren Kommentar anzeigen1 älteren Kommentar ausblenden
Les Beckham am 19 Apr. 2023
You are quite welcome.

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Axis Labels finden Sie in Help Center und File Exchange

R2023a

### Community Treasure Hunt

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

Start Hunting!