MATLAB For Loop Help: Plot SVAJ Accel Graph w/ Norton 5th Ed

  • MATLAB
  • Thread starter Chandlerw88
  • Start date
  • Tags
    Loop Matlab
In summary: It looks like you are trying to plot a graph of the acceleration of the SVAJ diagram for 3 of the SCCA Family of Functions with a theta range from 0 to Beta. You are getting an error because you are using a cell array instead of an array. The correct way to do this would be to use arrays and then calculate the acceleration constant using the formula provided. Once you have the acceleration constant, you can plot the graph for each zone using the corresponding equations. If you are still having trouble, you can refer to the figure on page 426 of the book Design of Machinery by Robert Norton 5th edition for guidance.
  • #1
Chandlerw88
1
0
I have created a code in MATLAB that can plot the acceleration graph of the SVAJ diagram for 3 of the SCCA Family of Functions with a theta range from 0 to Beta. I cannot for the life of me, figure out what I am doing wrong, maybe some fresh eyes can help me. Ignore the 'trial', I'm trying to work for home, and didn't want to buy matlab. If you have the book Design of Machinery by Robert Norton 5th edition, its the figure on pg. 426. Thanks in advance to anyone that can help me
My script reads:
Code:
Trial>> b={.25, .25, .5}
b =
  1×3 cell array
    [0.2500]    [0.2500]    [0.5000]
Trial>> d={.25, .75, .5}
d =
  1×3 cell array
    [0.2500]    [0.7500]    [0.5000]
Trial>> for n=1:1:3
p=b(n)
z=d(n)
%Step 2: Create acceleration constant
Ca = 4*pi^2/((pi^2-8)*(p^2-z^2)-2*pi*(pi-2)*p+pi^2);
%zone 1 info%
x1 = 0:0.01:(p/2);
y1 = Ca*sin(pi*x1/p);
%zone 2 info%
x2 = p/2:0.01:(1-z)/2;
y2 = Ca;
%zone 3 info%
x3 = (1-z)/2:0.01:(1+z)/2;
y3 = Ca*cos(pi*(x3-(1-z)/2)/z);
%zone 4 info*
x4 = (1+z)/2 :0.01:1-p/2;
y4 = -Ca;
%zone 5 info%
x5 = (1-p/2):0.01:1;
y5 = Ca*sin(pi*(x5-1)/p);

x = [x1 x2 x3 x4 x5];
y = [y1 y2 y3 y4 y5];

plot(x,y)
end
p =
  cell
    [0.2500]

z =
  cell
    [0.2500]
Undefined operator '^' for input arguments of type 'cell'.   <---- this this the last error I received
 
Physics news on Phys.org
  • #2
I don't understand why you are using cell arrays. You should be simply using arrays: b=[.25 .25 .5] and so on.
 

1. What is a for loop in MATLAB and how do I use it?

A for loop in MATLAB is a programming construct that allows you to iterate through a set of instructions a specified number of times. It is useful for automating repetitive tasks or performing calculations on a large set of data. To use a for loop, you need to define the starting value, ending value, and the increment or decrement for the loop. Then, the loop will run the specified instructions for each value in the defined range.

2. How can I plot a graph in MATLAB using the SVAJ Accel data from Norton's 5th edition?

To plot a graph in MATLAB using the SVAJ Accel data from Norton's 5th edition, you first need to import the data into MATLAB. Then, you can use the "plot" function to plot the data points on a graph. Make sure to label your axes and add a title to the graph for better visualization.

3. Can I customize the appearance of my graph in MATLAB?

Yes, you can customize the appearance of your graph in MATLAB by using various formatting options. For example, you can change the color, line style, and marker style of the plotted data points. You can also add a legend, gridlines, and annotations to your graph.

4. How do I save my plotted graph in MATLAB?

To save your plotted graph in MATLAB, you can use the "saveas" function. This function allows you to save the graph in a specified file format, such as PNG, JPEG, or PDF. You can also specify the resolution and size of the saved graph.

5. Is there a way to automate the process of plotting multiple graphs in MATLAB?

Yes, you can use a for loop to automate the process of plotting multiple graphs in MATLAB. You can create a loop that iterates through a set of data files and plots a graph for each file. This can save you time and effort, especially when dealing with a large amount of data.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
999
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
126
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • Introductory Physics Homework Help
Replies
1
Views
998
Back
Top