Coordinates In workspace to x1 y1 ,x2 y2

6 views (last 30 days)
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 Comments
Himanshu Tomar
Himanshu Tomar on 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 on 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.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 25 Jan 2016
Edited: Walter Roberson on 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 Comments
Himanshu Tomar
Himanshu Tomar on 27 Jan 2016
error says the Indices limit exceeds !
Himanshu Tomar
Himanshu Tomar on 27 Jan 2016
Thanx Walter , stephen and ev1 . Thanxalot

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!