I have an Excel file of multiple rows and columns. I want to plot the entire file as a 3D plot. The first row is X and the First column is Y. I have tried to read X,Y and Z with the below codes, but I faild.I want to insert this data into a 3D matrix, in which I could do some calculations on that and then plot it. How can I insert this Excel file into a 3D matrix? and How can I plot it? I have also attached the Excel file. Thanks
x=sample(1,2:22)
y=sample(2:102,1)
xSize=length(x);
ySize=length(y);
for i=1:xSize
for j=1:ySize
xP(i)=x(i);
yP(j)=y(j);
zP(i,j,j)=sample((i+1),(j+1))
end
end

6 commentaires

Geoff Hayes
Geoff Hayes le 28 Jan 2022
@Behrad Ze - where is the code to read the file? Or are you missing that code?
Behrad Ze
Behrad Ze le 28 Jan 2022
I am loading the code by selecting the rows and columns with matlab interface,and then importing them as a matrix.
What's the third dimension supposed to be/represent?
You apparently have an XY plane with the X,Y coordinates at the top and left side of a 2D array -- simply
Z=readmatrix('sample.csv'); % return the whole 2D array
X=XYZ(1,2:end); % pick first row for X
Y=XYZ(2:end,:); % and first column for Y
X=Z(2:end,2:end); % now save the response variable only for Z
After this to plot a surface or whatever, look at surf() and friends; later releases of MATLAB don't require the explicit construction of the XY grid points via meshgrid as did earlier.
But, there isn't a Z direction in the data to use as an index to a plane to create a 3D array; don't know what your trying to do there...
Voss
Voss le 28 Jan 2022
The data in sample.csv is a 101-by-21 matrix (not counting the first row and first column, which are X and Y indices). How would you like to manipulate a 101-by-21 matrix into a 3D matrix, i.e., what size should the 3D matrix be?
101-by-3-by-7?
101-by-7-by-3?
101-by-1-by-21?
101-by-21-by-1? (It already is this.)
3-by-7-by-101?
3-by-101-by-7?
etc.
Behrad Ze
Behrad Ze le 28 Jan 2022
Modifié(e) : Behrad Ze le 28 Jan 2022
All the cells except the first row and the first column are my Z direction.I have actually 21*101 values for the Z direction.
Behrad Ze
Behrad Ze le 28 Jan 2022
I am quite new to Matlab. I have plotted it using Origin,but I need to manipulate it using Matlab.I am not sure if it makes sense to use 3d matrix in this case.I have 21 X values, 101 Y values, and 21*101 Z values.I am really puzzled. What could the best option to store these values? Thank You

Connectez-vous pour commenter.

 Réponse acceptée

Voss
Voss le 28 Jan 2022
I think a 2D matrix is the way to go, since you have one value for each (x,y) point.
Here are some ways you might visualize your data. All of these ways create a surface object:
sample = readmatrix('sample.csv');
x=sample(1,2:end);
y=sample(2:end,1);
data = sample(2:end,2:end);
figure();
surf(x,y,data);
colorbar();
Then the same surface viewed from above:
figure();
surf(x,y,data);
colorbar();
view([0 90]);
Another way to do the same thing:
figure();
pcolor(x,y,data);
colorbar();

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Centre d'aide et File Exchange

Produits

Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by