Connecting Dots in a plot

Hello everyone!
I have 1 Vector (8x1 dimension) and 1 Array (3x1x8 dimension) and I want to connect each number of the vector with first element of each vector that belong to the array (this would mean 1x1x8)
My script works but I am struggling to connect the each point with a line, Can you help me ?
Here is my extract of code:
for i = 1:Nplies
zbar(i,1) = -(h + t)/2 + i*t;
theta = thetadb(i) * pi / 180;% ply i angle in radians, from bottom
theta_global(i,1) = thetadb(i);
c = cos(theta);
s = sin(theta);
T = [ c^2 s^2 -2*c*s; s^2 c^2 2*c*s; c*s -c*s (c^2 - s^2)];
T_inv = [c^2 s^2 c*s; s^2 c^2 -c*s; -2*c*s 2*c*s (c^2 - s^2)];
Qbar = T * Q * T_inv; %transformed reduced stiffness matrix
NT(:,:,i) = NTi + Qbar * abar * t * deltaT;
NT_plot(:,:,i) = NTi + Qbar * abar * t * deltaT;
figure(2)
plot (NT_plot(1,:,i),zbar(i,1),'dr')
xlabel('Loads in X')
ylabel ('Laminate Global Thickness [mm]')
legend ('NT across the Laminate')
hold on
grid on
line(NT_plot(1,:,i),zbar(i,1))
end

4 个评论

You are ploting your results in the for loop. Doing that, each new plot is a line, but with a single point.
I reccomand you to realise your plot after the loop. Then you can change line properties this way :
plot (NT_plot(1,:,:), zbar(:,1), 'LineStyle', '-')
or
h = plot (NT_plot(1,:,:), zbar(:,1), '-');
h.LineStyle = '-';
Thanks for your help, unfortunately is now telling me this:
Error using plot
Data cannot have more than 2 dimensions.
Error in MT_Global_laminate_analysis1 (line 117)
plot (NT_plot(1,:,:),zbar(:,1), 'LineStyle', '-.')
Yeah, matrix NT_plot has 3 dimension and plot function is for 2-D line plot.
I don't really understand your context, and I dont have your data. Try to plot in a loop, something like :
for dim = 1:size(NT_plot,3)
plot (NT_plot(1,:,dim), zbar(:,1), 'LineStyle', '-', 'DisplayName', num2str(dim))
end
or a 3D plot with : plot3, mesh, ...
I could make it work! Thanks for your help, was very useful

请先登录,再进行评论。

回答(0 个)

类别

产品

版本

R2019b

标签

Community Treasure Hunt

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

Start Hunting!

Translated by