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

 Respuesta aceptada

Star Strider
Star Strider el 13 de Mayo de 2021

1 voto

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 comentarios

Francesco Marchione
Francesco Marchione el 13 de Mayo de 2021
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
Francesco Marchione el 13 de Mayo de 2021
I tried like this, but it does not work.
"Matlab can only run a file with a valid name"
Star Strider
Star Strider el 13 de Mayo de 2021
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
Francesco Marchione el 13 de Mayo de 2021
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
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
Francesco Marchione el 14 de Mayo de 2021
Thank you so much
Star Strider
Star Strider el 14 de Mayo de 2021
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Interpolation en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 13 de Mayo de 2021

Comentada:

el 14 de Mayo de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by