How do I create a 3D plot using the messgrid command from data within an Excel file?
Mostrar comentarios más antiguos
I need help creating a 3D plot using data from an excel file. I went to have the three axis be temperature, frequency and Epsilon values. The first row of the excel file is the temperature starting from 160 to 60 in Celsius. The first column is the frequency in Hertz, while the values in the middle are the epsilon values for a specifc temperature and frequency.
Here is what I have so far. My main issue is that I am getting error while using the meshgrid command. To be specific I am getting the following error:
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
data_epp=readtable('Epsilon_Prime.xlsx'); % reads data
x=data_epp(1,3:end); % temperature(C)
y=data_epp(2:end,1); % freqeuncy(Hz)
z=data_epp(:,3:end); % epsilon prime
[X,Y}=meshgrid(x,y);
mesh(X,Y,z)
Respuestas (2)
data_epp=readtable('Epsilon_Prime.xlsx'); % reads data
x=data_epp{1,3:end}; % temperature(C)
y=data_epp{2:end,1}; % freqeuncy(Hz)
z=data_epp{2:end,3:end}; % epsilon prime
[X,Y]=meshgrid(x,y);
mesh(X,Y,z)
The meshgrid call is actually not necessary.
Try this —
T1 = readtable('Epsilon_Prime.xlsx')
T1.Var2 = str2double(T1.Var2)
x = T1{1,2:end};
y = T1{2:end,1};
z = fillmissing(T1{2:end,2:end}, 'nearest'); % Interpolate 'NaN' Elements
figure
mesh(x, y, z)
xlabel('X')
ylabel('Y')
zlabel('Z')
.
3 comentarios
Delonte Goodman
el 13 de Jul. de 2023
Delonte Goodman
el 13 de Jul. de 2023
Star Strider
el 14 de Jul. de 2023
Editada: Star Strider
el 14 de Jul. de 2023
I cannot duplicate that exactly, however I can get reasonably close.
Try this —
T1 = readtable('Epsilon_Prime.xlsx')
T1.Var2 = str2double(T1.Var2)
x = T1{1,2:end};
y = T1{2:end,1};
[X,Y] = ndgrid(x,y);
z = fillmissing(T1{2:end,2:end}, 'nearest'); % Interpolate 'NaN' Elements
F = scatteredInterpolant(X(:),Y(:),z(:));
L74 = F(74,0)
L66 = F(66,0)
figure
surf(x, y, z)
colormap(turbo)
hold on
plot3([1 1]*74,[0 0],[0.1 L74], '-.b', 'LineWidth',2)
plot3([1 1]*66,[0 0],[0.1 L66], '-.b', 'LineWidth',2)
hold off
% colorbar
zlim([0.1 max(zlim)])
Ax = gca;
Ax.ZScale = 'log';
xlabel('Temperature (°C)')
ylabel('Frequency (Hz)')
zlabel('\epsilon''')
view(5,10)
text(74, 0, 0.05, '74 °C (N)', 'Color','r', 'Rotation',-30, 'Horiz','left')
text(66, 0, 0.05, '66 °C (NF)', 'Color','r', 'Rotation',-30, 'Horiz','left')
The scatteredInterpolant call is simply used to define the upper ends of the blue dash-dot lines. It is otherwise not necessary. SPecifically see the documentation for the view function to change the axes orientation.
Your data do not appear to be exactly those of the provided plot image, so this is the best I can do.
Experiment to get different results.
EDIT — (14 Jul 2023 at 01:47)
Changed the view arguments.
.
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



