Trying to produce a plot of X vs P, using a for loop

조회 수: 1 (최근 30일)
Collin McKenzie
Collin McKenzie 2022년 2월 20일
답변: Anshika Chourasia 2022년 2월 24일
I'm fairly new to this, and I am trying to find forces at a variety of different points from 0 to 750. I have a for loop set up to do this, but the code only produces one value for x, and a blank plot. Looking for any help to point me in the right direction, or let me know what I could be doing wrong. Thanks.
clear;
clc;
P=zeros(1,750);
theta=zeros(1,750);
L=zeros(1,750);
F=zeros(1,750);
W=10;
for x = 1:750
theta(x)=atand(0.4/x);
L(x)=0.4/(sind(theta(x)));
F(x)=(W*0.5*9.8*cosd(theta(x))/L(x));
P(x)=F(x)*sind(theta(x));
end
plot(x,P(x));

답변 (1개)

Anshika Chourasia
Anshika Chourasia 2022년 2월 24일
Hi Collin,
According to my understanding, in your code snippet x contains a singular value and you’re trying to plot a single point.
To plot a set of coordinates connected by line segments specify X and Y as vectors of the same length in the "plot(X, Y)" function. Please refer this link for more information related to 2-D line plot.

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by