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!

1 comentario

Susan
Susan el 26 de Jul. de 2011
My plot perfectly works, it is just regarding the array part !

Iniciar sesión para comentar.

 Respuesta aceptada

Paulo Silva
Paulo Silva el 26 de Jul. de 2011

1 voto

SusanArray=[x;y]; %2 rows, first row is x and second is y
%each column is a pair of values

1 comentario

Susan
Susan el 26 de Jul. de 2011
Yeah I know that bit, but how can I actually take the values from x,y and store it there???? i dont know how to access the values created in the plot, i want each point (x1,y1),x2,y2),etc.. how can I get the values from the plot??

Iniciar sesión para comentar.

Más respuestas (2)

Walter Roberson
Walter Roberson el 26 de Jul. de 2011

1 voto

h = find(gca,'type','line');
xd = get(h, 'XData');
yd = get(h, 'YData');

7 comentarios

Susan
Susan el 26 de Jul. de 2011
Can you please explain to me the three lines.. Is it meant to be ..
h = find(x,y)
xd = get(h,x)
yd - get(h,y) ????
Oleg Komarov
Oleg Komarov el 26 de Jul. de 2011
findobj(gca,'type','line')
Susan
Susan el 26 de Jul. de 2011
Can you explain to me this?
Susan
Susan el 26 de Jul. de 2011
I did this but it resulted with empty array .. h =findobj(gca,'type',X)
disp(h)
Nathan Greco
Nathan Greco el 26 de Jul. de 2011
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
Susan el 26 de Jul. de 2011
I typed exactly the three line Walter suggested after the plot and I got an error..
Error using ==> find
Second argument must be a positive scalar integer.
Nathan Greco
Nathan Greco el 26 de Jul. de 2011
And he corrected his "find..." line to be "findobj..." within the comments.

Iniciar sesión para comentar.

Susan
Susan el 26 de Jul. de 2011

0 votos

Ok, I've read about this line you guys suggested h = find(gca,'type','line');... But what I am looking for is the actual values of the plot (x1,y1),(x1,y2) etc.. and from what I understood this line is not doing this..
Any Ideas how to get the plot values and store it in an array???

4 comentarios

Nathan Greco
Nathan Greco el 26 de Jul. de 2011
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
Susan el 26 de Jul. de 2011
Yeah I want the values that created my plot, I want to store it in an array..
Nathan Greco
Nathan Greco el 26 de Jul. de 2011
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
Susan el 26 de Jul. de 2011
Oh thank you very much.. I don't know why I was trying to work on the very long way.. Paulo's method worked.. Thanks a lot.. I was well confused :)

Iniciar sesión para comentar.

Categorías

Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 26 de Jul. de 2011

Community Treasure Hunt

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

Start Hunting!

Translated by