I have a variable X= [3,2,4,5] , Y=[5,3,3,6] , similarly many other in my workspace. How do I plot these variables individually. I am using a list box in which all these variables are listed. To plot line X the coordinates would be x1=3, y1=2 ,x2=4 ,y2=5, so how can i convert the 4 element vector(X,Y,..) into a x1,y1,x2,y2 format . thanx in advance

7 commentaires

Stephen23
Stephen23 le 25 Jan 2016
Modifié(e) : Stephen23 le 25 Jan 2016
What do you hope to achieve by having lots of separate variables? Have you tried plotting the vectors? What does this do that you do not want? Please explain why you need separate variables to plot.
Stephen23
Stephen23 le 25 Jan 2016
Modifié(e) : Stephen23 le 25 Jan 2016
It seems that you do not use the Y values at all, only the X values:
x1=3, y1=2 ,x2=4 ,y2=5 <- these seem to be the X values
So where are the Y values used? Can you please explain the task with complete input and output data.
Walter Roberson
Walter Roberson le 25 Jan 2016
The user has a number of four-element vectors, and wants a way to break each four-element vector into variables x1, y1, x2, y2.
Himanshu Tomar
Himanshu Tomar le 25 Jan 2016
I have to plot those vector lines individually after they are listed in listbox , when i click on them the line gets plotted. So X,Y.. and many other four element vectors are listed in my listbox, when i click on any one of them and then click plot. the vector should get plotted. But I cannot convert the four elements of vector into x1,y1 & x2,y2 from my workspace, where they are saved as an array for ex:- X[1,2,3,4]
Walter Roberson
Walter Roberson le 25 Jan 2016
Are they listed by variable name or by content of the variables in the list box? How are you converting the list box selection into the appropriate content?
Himanshu Tomar
Himanshu Tomar le 27 Jan 2016
The workspace variables are listed in the listbox. I can just set the selection of variable selected in the listbox and then while plotting i want to plot the 4 elements as x1,y1 and x2,y2. How can I do that
Walter Roberson
Walter Roberson le 27 Jan 2016
I need to see the code that sets the String property of your listbox, and I need to see whatever code uses the Value property of your listbox to decide what is being done.

Connectez-vous pour commenter.

 Réponse acceptée

Walter Roberson
Walter Roberson le 25 Jan 2016
Modifié(e) : Walter Roberson le 25 Jan 2016
x1 = Variable(1);
y1 = Variable(2);
x2 = Variable(3);
y2 = Variable(4);
Or
Variable_cell = num2cell(Variable);
[x1, y1, x2, y2] = Variable_cell{:};
Now if the point was to plot the variables then
plot(Variable([1 3]), Variable([2 4]))
with no need to break it into x1/y1/x2/y2

3 commentaires

plot(Variable([1 3]), Variable([2 4]))
is the best solution.
Himanshu Tomar
Himanshu Tomar le 27 Jan 2016
error says the Indices limit exceeds !
Himanshu Tomar
Himanshu Tomar le 27 Jan 2016
Thanx Walter , stephen and ev1 . Thanxalot

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Line Plots dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by