Was doing some MATLAB homework and couldn't get a graph to come up just a table was looking for some help.

조회 수: 1 (최근 30일)
3. (35 pts) Table and Graph. Write a MATLAB program (script or .m file) to create a table showing radius R
and volume V for a sphere as R varies from 0 cm to 50 cm. Also graph volume vs radius. Specifically:
Write a MATLAB program (script or .m file).
Begin with the block of comments as described above. Add other comments throughout the program.
Use a range variable to assign the values of R from 0 to 50 cm in increments of 5 cm.
Use a formula on the vector above to create another vector for the volume of the sphere. Note that a dot
operation will be required.
Combine the transpose of the two vectors to create a new vector (table).
Display the problem number and your name before displaying the table.
Display the table and include a table heading (with units).
No special formatting is required for this problem.
Extra credit: Use fprintf to use 0 digits after the decimal point for the radius and 2 digits after the
decimal point for the volume.
Form a graph of volume vs radius. Add major gridlines. Label the axes. Add a title.
Print the script, the output table, and the graph.
This is my homework instructions and bellow is the code that i have.
R = 0:5:50;
V = 4/3*pi*R.^3;
sTable = [R' V'];
disp('HW #6 - Evan Melanson')
HW #6 - Evan Melanson
disp('Problem #3')
Problem #3
colNames = {'R','V'};
disp('Radius R (cm) | Volume V (cm^3)')
Radius R (cm) | Volume V (cm^3)
fprintf([repmat('\t %.2f \t', 1, size(sTable,2)) '\n'], sTable');
0.00 0.00 5.00 523.60 10.00 4188.79 15.00 14137.17 20.00 33510.32 25.00 65449.85 30.00 113097.34 35.00 179594.38 40.00 268082.57 45.00 381703.51 50.00 523598.78
plot(R,V)
xlabel('R (cm)')
ylabel('V (cm^3)')
  댓글 수: 2
Adam Danz
Adam Danz 2021년 11월 18일
I used the run feature to run the code in your question which produces outputs and the plot. Perhaps the plot is burried in another window or docked in your Matlab environment window.
evan melanson
evan melanson 2021년 11월 18일
Thank you so much i think it is too but thanks for the information i thought i had done something wrong.

댓글을 달려면 로그인하십시오.

답변 (1개)

Prateek Rai
Prateek Rai 2021년 11월 21일
Hi,
You can use the "figure" function before "plot" to create a figure window for your graph.
Your code will look like:
figure(1)
plot(R,V)
xlabel('R (cm)')
ylabel('V (cm^3)')
You can refer to the figure MathWorks documentation page to find more on creating a figure window.
  댓글 수: 1
Image Analyst
Image Analyst 2021년 11월 21일
Not sure why that's needed. In my experience (regular desktop MATLAB) if you plot something with no figure yet showing, it will automatically create a figure for you.

댓글을 달려면 로그인하십시오.

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by