Converting 2D plot into a 3D with 3rd axis being steps.

Hi.
I have a for loop, which loads data from set of an excel files as temperory table with two columns and plots a 2d plot. Using the 'hold on; option, i'm able to get a 2D graph which includes data from all the files. The excel file is data recorded from experiment to test degradation. Each excel file represents evolution of the peaks. I would like to have a 3D plot with constant depth - as a funtion of steps (which I can include as a vector as my steps are limited to 7). So basically it's like converting a 2D plot to 3D to avoid cluttering of information. An example that can be taken is that of 'asin(bx)' funtion with changing values of a and b. The only problem i'm facing is that these values are loaded as vectors and not matrices. Could anyone suggest me a simple way to use 3 vectors of which 2 vectors are of same length (approx 300 paired data points), and the third vector of different length (steps - [1 2 3 4 5 6 7]) to be plotted in a 3D graph?

Respuestas (1)

Run this example
x = linspace(0, 2*pi, 1000);
B = [1 2 3 4 5];
ax = axes();
hold(ax);
view(ax, 3)
grid on;
for i=1:numel(B)
b = repmat(B(i), size(x));
y = sin(b.*x);
plot3(x, b, y);
end
xlabel('x');
ylabel('b');
zlabel('y');

5 comentarios

Ameer, That something to very similar what I need. Is it possible to connect the curves via surfaces? something as shown in this image? Instead of i/mA/cm2 I would prefer the vector B of your code. I tried useing surf and mesh, doesnt seem to work.
If you want to use surf() then you first need to calculate all the points and then call surf(). For example
x = linspace(0, 2*pi, 100);
B = [1 1.2 1.4 1.6 1.8 2];
[xg, Bg] = meshgrid(x, B);
y = zeros(size(xg));
for i=1:numel(B)
b = B(i);
y(i,:) = sin(b.*x);
end
ax = axes();
surf(xg, Bg, y);
xlabel('x');
ylabel('b');
zlabel('y');
Thank you Ameer! I'm almost there but needed the graph to look more professional. The code is here below. I don't get smooth overlap of curves. The resulting graph is below. Is there a way for the curves to be smoother between 'b' values?
x=TmpTable.Frequency; % This is loaded by an external for loop whic is for i=1:NbrDRT
B = (1:NbrDRT); %NbrDRT=7; i.e number of steps= number of files
[xg, Bg] = meshgrid(x, B);
y = zeros(size(xg));
for l=1:numel(B(i))
b = B(i);
y(i,:)=TmpTable.DRT; % also from external forloop
figure(3)
s=surf(xg, Bg, y, 'FaceAlpha',1,'FaceColor',[173,216,230]/255);
% colormap jet;
set(gca,'XScale','log')
hold on
end
%colorbar
xlabel('x');
ylabel('b');
zlabel('y');
How are you creating the figure is not clear. Can you share the .fig file for this surface?
I have also attached the code in my previous comment. Here is the .fig file

Iniciar sesión para comentar.

Categorías

Más información sobre 2-D and 3-D Plots en Centro de ayuda y File Exchange.

Productos

Versión

R2019b

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by