MATLAB 3D Plot assistance needed

Click For Summary
SUMMARY

The discussion centers on creating a 3D plot in MATLAB to visualize the temperature distribution along a metal rod heated at one end. The user, Max, has six text files containing temperature data, which he has successfully loaded into vectors. He is attempting to utilize the meshgrid and mesh functions but encounters an error indicating that the Z variable must be a matrix rather than a vector. The solution involves correctly formatting the Z data to match the dimensions required for the mesh plot.

PREREQUISITES
  • Familiarity with MATLAB syntax and commands
  • Understanding of 3D plotting functions in MATLAB, specifically meshgrid and mesh
  • Basic knowledge of matrix operations in MATLAB
  • Experience with loading data from text files in MATLAB
NEXT STEPS
  • Learn how to format data into matrices for 3D plotting in MATLAB
  • Explore the surf function for enhanced surface plotting in MATLAB
  • Research MATLAB's meshgrid function for creating coordinate grids
  • Investigate error handling in MATLAB to troubleshoot common plotting issues
USEFUL FOR

This discussion is beneficial for MATLAB users, particularly those involved in scientific computing or data visualization, as well as students and professionals working with temperature data analysis and 3D plotting techniques.

maxtor101
Messages
22
Reaction score
0
Hi guys! Kinda stuck here..

I'm trying to plot the temporal temperature distribution across a metal rod of length 1 meter. The rod is heated at one end and the temperature is measured every 5 cm along the meter rod every 10 minutes for an hour.

Basically I have 6 text files, each containing 20 temperature values. This will go on the z-axis.
Then I have a vector y = [0:5:100]; for the position along the rod. Then I have another vector t containing the times at which i measured the temperature.

So far I've used the load command to read in the data from the text files into 6 vectors. And I have the "position" vector y = [0:5:100]; . I'm not sure how to make this into a three dimensional plot though, I'm very new to matlab.

Any help would be greatly appreciated!
Thanks!
Max
 
Physics news on Phys.org
http://www.mathworks.com/help/techdoc/learn_matlab/f3-40352.html

You need to create a meshgrid and use surf.
 
Thanks for your reply, however I'm still unsure as to handle the 6 different text files.

Code:
load plot1.txt
load plot2.txt
load plot3.txt
load plot4.txt
load plot5.txt
load plot6.txt

for i=1:6,
    [X] = meshgrid(0:10:60);
    [Y] = meshgrid(0:5:100);       
    [Z] = plot(i);
    mesh(X,Y,Z,'EdgeColor','black')
end

I'm guessing it will be something along the lines of this...?
 
But this throws up an error
Code:
 ? Error using ==> mesh at 80
Z must be a matrix, not a scalar or vector.

Error in ==> plots at 14
    mesh(X,Y,Z,'EdgeColor','black')

Any ideas?
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K