Passing a field from a user type vector to plot using Plots

When I pass a dummy array to the plot routine everything is fine. When I pass a vector from a field of a user define type I get an error. The error is: type Array does not contain a field XX. Is there a way to do this without creating a dummy array from the user type field.

Welcome to the forums! It sounds a bit like you’ve got a syntax bug somewhere - if you’re giving a vector, wherever it comes from, it should work. But it’s hard to know exactly what’s happening without seeing the code. Can you make a minimum working example?

Also, take a look at this post, which has some helpful suggestions about how to post a question and maximize the chances that someone can help.

2 Likes

Thanks for your thoughts. I’ve am now including an example to help explain my error? See below

This runs and plots the result
using Plots
feed = zeros(10,2)
dummy = zeros(10)
mutable struct Feed
x::Float64
y::Float64
end
feed = [Feed(100.0,40.0) for _ = 1:10]
for i in 1:10
dummy[i] = feed[i].x
end
plot(1.0:10.0,dummy[1:10])

This gave me a load error type Array has no field x:
using Plots
feed = zeros(10,2)
dummy = zeros(10)
mutable struct Feed
x::Float64
y::Float64
end
feed = [Feed(100.0,40.0) for _ = 1:10]
plot(1:10,feed[1:10].x)