I do have a excel file with 3 columns (x y z). I wanna import them to Matlab, and plot a nice surface Plot.i might have to interpolate?

댓글 수: 2

Rik
Rik 2019년 12월 20일
If it is a full grid of x and y, there will be no need for interpollation. Can you share your actual data, or a functional equivalent?
Verena Salan
Verena Salan 2019년 12월 20일
here are my data

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

답변 (2개)

Rik
Rik 2019년 12월 20일

1 개 추천

No interpollation required, just a conversion to a 2D matrix. You can adapt the syntax of accumarray if you do have any missing values (by default it will fill with 0).
num=xlsread('test1.xlsx');
x=num(:,1);
y=num(:,2);
P=num(:,3);
%find the unique x and y values and use them as indices to fill the Z
[X,~,x_]=unique(x);
[Y,~,y_]=unique(y);
Z=accumarray([x_,y_],P);
[X,Y]=ndgrid(X,Y);
surf(X,Y,Z)

댓글 수: 10

Verena Salan
Verena Salan 2019년 12월 20일
Hi
thank you very much.
I got 2 hills. Do you know how i can get the volume from the right hill?
ME
ME 2019년 12월 20일
편집: ME 2019년 12월 20일
Nice solution. You could also use the reshape function to get your z-data into the correct format.
I had assumed the data wouldn't be uniform over x and y - I suppose I should ask more questions in future!
Verena Salan
Verena Salan 2019년 12월 20일
@ME : how would it look like with the reshape function?
Rik
Rik 2019년 12월 20일
The reshape method has the downside that you need to be sure about the orientation of your data. It will also fundamentally break if you don't have a complete grid.
Also note that surf will handle non-uniform spacing of values, it just needs a full grid (which is allowed to contain NaN values).
As to the question of how to get the volume: figure out a way to set the other hill to 0 and then use a 2D integration to find the volume.
Verena Salan
Verena Salan 2020년 1월 2일
Because of the volume, can't figure out how to do that.
Rik
Rik 2020년 1월 2일
What have you tried?
Verena Salan
Verena Salan 2020년 1월 6일
Does anyone has any ideas how i could get the volume? don't know how.
Rik
Rik 2020년 1월 6일
What have you tried so far?
Verena Salan
Verena Salan 2020년 1월 6일
don't know how
Rik
Rik 2020년 1월 6일
On a conceptual level, what would you do? If you needed to do it on paper, what would your approach be?

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

ME
ME 2019년 12월 20일

0 개 추천

I think you are correct about the need to interpolate. You could try having a read of the link below - that should give you some good pointers.

카테고리

태그

질문:

2019년 12월 20일

댓글:

Rik
2020년 1월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by