3D plot from excel
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
I have a file excel with x,y coordinates and stresses for z coordinate in order to plot a 3D surface.
How can I get this surface with latex interpreter and colorbar?
I attach the excel file.
Thanks
채택된 답변
Star Strider
2021년 5월 13일
1 개 추천
Try something like this —
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/616758/Shear%20stress%20adhesive.xlsx', 'VariableNamingRule','preserve');
% First10Rows = T1(1:10,:)
T1Sz = size(T1)
T1Sz = 1×2
69696 3
VarNames = T1.Properties.VariableNames;
N = 50; % Interpolation Matrix Size
xv = linspace(min(T1{:,1}), max(T1{:,1}), N); % Create Vector
yv = linspace(min(T1{:,2}), max(T1{:,2}), N); % Create Vector
[Xm,Ym] = ndgrid(xv,yv); % Create Interpolation Matrices
Zm = griddata(T1{:,1}, T1{:,2}, T1{:,3}, Xm, Ym); % Interpolate
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
figure
surfc(Xm, Ym, Zm)
grid on
hcb = colorbar;
hcb.TickLabelInterpreter='latex';
xlabel(VarNames{1}, 'Interpreter','latex')
ylabel(VarNames{2}, 'Interpreter','latex')
zlabel(VarNames{3}, 'Interpreter','latex')

Experiment to get different results.
.
댓글 수: 7
Thank you Star.
In the first line:
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/616758/Shear%20stress%20adhesive.xlsx', 'VariableNamingRule','preserve');
shall I write the path to the file in my pc? For example:
T1 = readtable('C:\Users\MARCHIONE\Desktop\Shear%20stress%20adhesive.xlsx', 'VariableNamingRule','preserve');
Forgive me, but I am a very beginner.
Thanks so much
Francesco Marchione
2021년 5월 13일
I tried like this, but it does not work.
"Matlab can only run a file with a valid name"
Star Strider
2021년 5월 13일
As always, my pleasure!
Your readtable call should be:
T1 = readtable('Shear stress adhesive.xlsx', 'VariableNamingRule','preserve');
or:
T1 = readtable('C:\Users\MARCHIONE\Desktop\Shear stress adhesive.xlsx', 'VariableNamingRule','preserve');
(or something similar, such as you posted, appropriate to your MATLAB installation), since I assume you are reading it from a directory on your MATLAB path.
(The online Run application here allows us to copy the full file name and run it on MATLAB Answers, so that accounts for the full directory path being part of the file name in the code I posted. That would work if you decided to use my code and run it here, however not on your own computer.)
.
Francesco Marchione
2021년 5월 13일
Now I would like to format the colorbar label: I would like to have it in the format 2.00 x 10^4 with every first number with two decimals and the exponential following.
I wrote:
set(hcb,'ColorScale','exp',num2str(tix,'%.1f'))
So, I managed to have the exponent but I could not set the number of decimals.
Thank you so much

Star Strider
2021년 5월 14일
We must be using different data, since the magnitude of the z-axis data is nowhere near
. Also, the set call does not work in R2021a, so I went property spelunking to find the version that works in R2021a. Those results are part of this Comment.
In any event, I cannot get the tick labels to work as you would like them to. I have no idea what the problem is.
Try this —
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/616758/Shear%20stress%20adhesive.xlsx', 'VariableNamingRule','preserve');
% First10Rows = T1(1:10,:)
% T1Sz = size(T1)
VarNames = T1.Properties.VariableNames;
N = 50; % Interpolation Matrix Size
xv = linspace(min(T1{:,1}), max(T1{:,1}), N); % Create Vector
yv = linspace(min(T1{:,2}), max(T1{:,2}), N); % Create Vector
[Xm,Ym] = ndgrid(xv,yv); % Create Interpolation Matrices
Zm = griddata(T1{:,1}, T1{:,2}, T1{:,3}, Xm, Ym); % Interpolate
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
figure
surfc(Xm, Ym, Zm)
grid on
hcb = colorbar;
hcb.TickLabelInterpreter='latex';
% ColorbarRulerProperties = hcb.Ruler
hcb.Ruler.Exponent = -1;
hcb.Ruler.TickLabelFormat = '%5.2f';
% tix = hcb.Ticks;
% expstr = @(x) [x(:).*10.^ceil(-log10(abs(x(:)+(x==0)))) floor(log10(abs(x(:)+(x==0))))];
% tixexp = expstr(tix(:))
% tixexplbl = compose('%.2f \\times 10^{%2d}',[tixexp(:,1) fix(tixexp(:,2))])
% hcb.TickLabels = tixexplbl;
xlabel(VarNames{1}, 'Interpreter','latex')
ylabel(VarNames{2}, 'Interpreter','latex')
zlabel(VarNames{3}, 'Interpreter','latex')

Except for ‘ColorbarRulerProperties’ assignment (that displays the appropriate properties), the commented-out lines create the correct tick labels, although the tick labels the code creates (for whatever reason) do not display at all. The result of the compose call are correct. I tried several different formats, however they all refuse to create colorbar ticks.
In the end, I went with what I could get to work.
.
Francesco Marchione
2021년 5월 14일
Thank you so much
Star Strider
2021년 5월 14일
As always, my pleasure!
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Interpolation에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
