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 日
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 件のコメント
Francesco Marchione
2021 年 5 月 13 日
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!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
