필터 지우기
필터 지우기

Read a 3D matrix from Excel file

조회 수: 7 (최근 30일)
Behrad Ze
Behrad Ze 2022년 1월 28일
댓글: Behrad Ze 2022년 1월 28일
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
Behrad Ze
Behrad Ze 2022년 1월 28일
편집: Behrad Ze 2022년 1월 28일
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 2022년 1월 28일
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

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

채택된 답변

Voss
Voss 2022년 1월 28일
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();
  댓글 수: 1
Behrad Ze
Behrad Ze 2022년 1월 28일
Thanks for your answer. It worked!

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by