Read a 3D matrix from Excel file

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 comentarios

Geoff Hayes
Geoff Hayes el 28 de En. de 2022
@Behrad Ze - where is the code to read the file? Or are you missing that code?
Behrad Ze
Behrad Ze el 28 de En. de 2022
I am loading the code by selecting the rows and columns with matlab interface,and then importing them as a matrix.
dpb
dpb el 28 de En. de 2022
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 el 28 de En. de 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 el 28 de En. de 2022
Editada: Behrad Ze el 28 de En. de 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 el 28 de En. de 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

Iniciar sesión para comentar.

 Respuesta aceptada

Voss
Voss el 28 de En. de 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();

Más respuestas (0)

Categorías

Productos

Versión

R2021b

Preguntada:

el 28 de En. de 2022

Comentada:

el 28 de En. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by