Read a 3D matrix from Excel file
Afficher commentaires plus anciens
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
le 28 Jan 2022
@Behrad Ze - where is the code to read the file? Or are you missing that code?
Behrad Ze
le 28 Jan 2022
dpb
le 28 Jan 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
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
le 28 Jan 2022
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


