How to plot a number of parametric/vector equations from data in Excel?

I would like to input a number of vector equations of the form V = A + tB. I have an excel spreadsheet containing the required data, in which the position and direction vectors A and B respectively are defined with columns for x, y and z values. I have tried to use something of the like:
t = linspace(0, 2*pi);
x = data(:,1) + t.*data(:,2)
y = data(:,3) + t.*data(:,4)
z = data(:,5) + t.*data(:,6)
plot3(x,y,z)
But it does not yield what it should. Anyone can help me figure this out? What am I doing wrong and how can I fix it?
EDIT: I have specific vectors for specific values of t. In my table, I could choose to include the column for values of t. Does this change anything or do I just need to alter my linspace values?
EDIT2: Here is the input you gave me that I adjusted. The figure is blank, just axis. bpbondsA = dataA and bpbondsB = dataB
N = 22 ;
bpbondsA = rand(N,3) ;
bpbondsB = rand(N,3) ;
xA = bpbondsA(:,1) ; xB = bpbondsB(:,1) ;
yA = bpbondsA(:,2) ; yB = bpbondsB(:,2) ;
zA = bpbondsA(:,3) ; zB = bpbondsB(:,3) ;
t = linspace(0,12.56637,22) ;
Vx = cell(N,1) ; Vy = cell(N,1) ; Vz = cell(N,1) ;
figure
hold on
for i =1:N
Vx{i} = xA(i)+t*xB(i) ;
Vy{i} = yA(i)+t*yB(i) ;
Vz{i} = zA(i)+t*xB(i) ;
plot3(Vx{i},Vy{i},Vz{i})
EDIT3: Attached the excel spreadsheet with the data on.

 Accepted Answer

Let dataA and dataB be (x,y,z) points for A and B read from excel file.
N = 10 ;
dataA = rand(N,3) ;
dataB = rand(N,3) ;
xA = dataA(:,1) ; xB = dataB(:,1) ;
yA = dataA(:,2) ; yB = dataB(:,2) ;
zA = dataA(:,3) ; zB = dataB(:,3) ;
t = linspace(0,2*pi) ;
Vx = cell(N,1) ; Vy = cell(N,1) ; Vz = cell(N,1) ;
figure
hold on
for i =1:N
Vx{i} = xA(i)+t*xB(i) ;
Vy{i} = yA(i)+t*yB(i) ;
Vz{i} = zA(i)+t*xB(i) ;
plot3(Vx{i},Vy{i},Vz{i})
end

17 Comments

Thank you I will try this now!
The result is a white plot, no points shown. I went into the plot browser and only the axis is indicated as a plot. Also, what does N represent? Im trying to understand the inputs you have put in.
N is number of points to make random data. Attach your excel sheet....it is a easy job.
% [num,txt,raw] = xlsread('DATA - Sheet1.csv') ;
num = [0 1 0 0 -1.74411 -0.66806 0
0.5984 0.82624 0.56332 0.31619 -1.06472 -1.53447 0
1.1968 0.36534 0.93087 0.63238 -0.01532 -1.86762 0
1.7952 -0.22252 0.97493 0.94857 1.03941 -1.55173 0
2.39359 -0.73305 0.68017 1.26476 1.73292 -0.69658 0
2.99199 -0.98883 0.14904 1.58095 1.8242 0.40065 0
3.59039 -0.90097 -0.43388 1.89714 1.28153 1.35864 0
4.18879 -0.5 -0.86603 2.21333 0.2935 1.84447 0
4.78719 0.07473 -0.9972 2.52952 -0.79653 1.68931 0
5.38559 0.62349 -0.78183 2.84571 -1.60974 0.94708 0
5.98399 0.95557 -0.29476 3.1619 -1.86354 -0.12429 0
6.58238 0.95557 0.29476 3.4781 -1.46971 -1.15246 0
7.18078 0.62349 0.78183 3.79429 -0.56513 -1.78013 0
7.77918 0.07473 0.9972 4.11048 0.53585 -1.78916 0
8.37758 -0.5 0.86603 4.42667 1.45061 -1.17642 0
8.97598 -0.90097 0.43388 4.74286 1.86125 -0.15484 0
9.57438 -0.98883 -0.14904 5.05905 1.62506 0.92054 0
10.17278 -0.73305 -0.68017 5.37524 0.82413 1.67602 0
10.77117 -0.22252 -0.97493 5.69143 -0.2632 1.84904 0
11.36957 0.36534 -0.93087 6.00762 -1.25907 1.37948 0
11.96797 0.82624 -0.56332 6.32381 -1.81738 0.43052 0
12.56637 1 0 6.64 -1.74411 -0.66806 0
];
N = size(num,1) ;
dataA = num(:,1:3) ;
dataB = num(:,4:6) ;
xA = dataA(:,1) ; xB = dataB(:,1) ;
yA = dataA(:,2) ; yB = dataB(:,2) ;
zA = dataA(:,3) ; zB = dataB(:,3) ;
t = linspace(0,2*pi) ;
Vx = cell(N,1) ; Vy = cell(N,1) ; Vz = cell(N,1) ;
figure
hold on
for i =1:N
Vx{i} = xA(i)+t*xB(i) ;
Vy{i} = yA(i)+t*yB(i) ;
Vz{i} = zA(i)+t*xB(i) ;
plot3(Vx{i},Vy{i},Vz{i})
end
N = size(num,1) ;
dataA = num(:,1:3) ;
dataB = num(:,4:6) ;
xA = dataA(:,1) ; xB = dataB(:,1) ;
yA = dataA(:,2) ; yB = dataB(:,2) ;
zA = dataA(:,3) ; zB = dataB(:,3) ;
t = linspace(0,2*pi) ;
Vx = cell(N,1) ; Vy = cell(N,1) ; Vz = cell(N,1) ;
figure
hold on
for i =1:N
Vx{i} = xA(i)+t*xB(i) ;
Vy{i} = yA(i)+t*yB(i) ;
Vz{i} = zA(i)+t*xB(i) ;
plot3(Vx{i},Vy{i},Vz{i})
end
You ll have to guide me through it, it really isnt working for me. Im getting errors.
I am getting the figure as attached...What errors you getting?
Error using xlsread
Not enough input argument
Exception in thread ....
at .... (and then a whole list of things)
I created a variable for dataA and dataB, correct?
Could it be I dont actually have Microsoft Office on laptop, therefore no Excel? I can download the file, but cant open it
Also, the figure you attached does not look like what it should yield. It should be a 3D plot, and the lines should be contained in a cylinder, each line going from opposite sides.
Okay now it did it thank you ! Its not what I wanted, but I don't think we ll get there: I ll input them by hand.
Massive thank you tho, for the patience and knowledge!
You can put them in text file and use load or importdata.
Put the data in text file instead of excel file.
Yes but it will yield ultimitaly the same plot

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!