Newbie Asks: Plotting MATLAB Commands Output in PF

In summary: If you want to save the plot to a file, you can use "savefig" followed by the filename you want to save the plot to. For example, "savefig myfile.png".In summary, your code has five vectors (Hv) and you want to plot all of them at once. You can use the ":" syntax to set "h" as the whole k-th row of the y matrix. You can also use the "subplot" command to move to the next subplot. You can also use the "figure" command to create a figure and then use the "Hv" variable to set the figure's title. Finally, you can use the "plot" command
  • #1
FlvD
4
0

Homework Statement


Hello all, I'm new to PF..Pls help..
I'm stuck in the following query.

I've MATLAB commands as follows:

Hv=[1,2,3,4,5]
for i=1:5
tspan=[1 30]
h0=Hv(i)
[t,h]=ode45[expression]
plot(t,h)
end

And here i need to see induvidual plots of my 5 results..I donno to save and then plot. Pls help.



Homework Equations





The Attempt at a Solution

 
Physics news on Phys.org
  • #2
Hello.

First of all, when putting code in the posts, there's a nifty little command of ['code']insertcodehere[/'code'] that you can use that really tidies things up (without the apostrophes of course). So it'd look like this:

Code:
Hv=[1,2,3,4,5]
for i=1:5
tspan=[1 30]
h0=Hv(i)
[t,h]=ode45[expression]
plot(t,h)
end

Okay, so I'm not exactly sure what you're asking... but first of all, are you getting any errors? What is your output right now? It's difficult to help without knowing the expression you're putting into the ode solver.

However, if this helps there are some commands that could help you "save and plot results." One is the subplot command. Look into using your iteration variable (i) to move to the next subplot. Or you could simply have the figure number be dependent on i as well.

So something like:

Code:
figure(1)
Hv=[1,2,3,4,5]
for i=1:5
tspan=[1 30]
h0=Hv(i)
[t,h]=ode45[expression]

subplot(5,1,i)
plot(t,h)
end

Like I said, let me know if I'm not addressing your question, as I'm a bit unsure as to what you're asking.
 
  • #3
Hi Flvd, you need to put all of your "h" vector solutions into a single matrix if you want a single plot command to plot them all simultaneously. The ":" syntax is really useful here. For example, if h is a row vector then "y(k,:) = h" sets "h" as the whole k-th row of the y matrix.

So you need something like this :

Code:
Hv=[1,2,3,4,5]
tspan=[1 30]               % No need to put this in the loop

for k=1:5                  % Best to leave "i" as pre-defined constant = sqrt(-1)
  h0 = Hv(k)
  [t,h] = ode45[expression] % Presumably "expression" includes the function an init conditions
  y(k,:)=h
end                         % You need to end the for loop here

plot(t,y)
 

What is "Newbie Asks: Plotting MATLAB Commands Output in PF"?

"Newbie Asks: Plotting MATLAB Commands Output in PF" is a question posed by a newcomer to the MATLAB programming language, asking for guidance on how to plot the output of MATLAB commands in the PF (Polar Format) format.

Why would someone want to plot MATLAB commands output in PF?

Plotting MATLAB commands output in PF can be useful for visualizing complex data in a polar coordinate system, which can provide insights and reveal patterns that may not be easily visible in a Cartesian coordinate system.

What are the steps for plotting MATLAB commands output in PF?

The steps for plotting MATLAB commands output in PF include: 1) Generating the data using MATLAB commands, 2) Converting the data to polar coordinates using the "cart2pol" function, 3) Plotting the data using the "polar" function, and 4) Customizing the plot as desired.

Are there any limitations when plotting MATLAB commands output in PF?

Yes, there are some limitations when plotting MATLAB commands output in PF. For example, the data must be in the correct format (polar coordinates) for the "polar" function to work properly, and the plot may not be as visually intuitive as a Cartesian plot for some types of data.

Can I save and export the PF plot created from MATLAB commands?

Yes, you can save and export the PF plot created from MATLAB commands just like any other plot. You can use the "saveas" or "exportgraphics" functions to save the plot as an image file, or you can use the "print" function to save it as a PDF or other document format.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
2
Views
809
  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
982
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Advanced Physics Homework Help
Replies
6
Views
2K
Back
Top