Array problem
显示 更早的评论
Hey every1, I am actually having trouble with arrays!! I have my plot and is underneath and it is not saved in array at the moment but I would like to story it in array so I should have a value for[x1,y1] in an array.. the question is how can I get the values of the plots and store it in an array???
x = linspace(min(Sa),max(Sa),100);
y = pchip(Sa,lambda(Sa),X);
plot(x,y)
a [x,y] then is it by looping through it and if it is how can we say then the next value in x and y.. I want to store each pair value(x,y) of the plot in an array???
Your help will be appreciated!
采纳的回答
更多回答(2 个)
Walter Roberson
2011-7-26
h = find(gca,'type','line');
xd = get(h, 'XData');
yd = get(h, 'YData');
7 个评论
Susan
2011-7-26
Oleg Komarov
2011-7-26
findobj(gca,'type','line')
Susan
2011-7-26
Susan
2011-7-26
Nathan Greco
2011-7-26
After you create your plot, type the lines Walter provided you.
findobj(gca,'type','line') will return the handle of the line object on your current plot. With this handle, you can retrieve the x and y data by using get(h,'XData') and get(h,'YData') respectively...
Susan
2011-7-26
Nathan Greco
2011-7-26
And he corrected his "find..." line to be "findobj..." within the comments.
Susan
2011-7-26
0 个投票
4 个评论
Nathan Greco
2011-7-26
Please be more precise. Are the values on the plot that you are trying to retrieve the same ones that you used to create the plot? Are you trying to take smaller stepped values from the plot? Saying (x1,y1) etc. is not very helpful.
Susan
2011-7-26
Nathan Greco
2011-7-26
Are they not already stored in arrays? If I'm not mistaken, that is exactly what your original x and y arrays are. If you wanted them in one array, just concatenate them together as Paulo answered. If you wanted to retrieve that same data from the plot (why? I don't know), follow Walter's method, replacing his "h = find(gca,'type','line');" with "h = findobj(gca,'type','line');". If this doesn't work for you, please say why not.
Susan
2011-7-26
类别
在 帮助中心 和 File Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!