I have the following data:
M = 1000; % [seconds]
D = 50; % number of masses
t = [0:dt:M];
y = randn(length(t),1); % [unitless] amplitude
z = [1:1:2*D]; % [unitless] number of eigenfrequencies
data = [t,y,z];
I would like to create a surface plot of data
where the x-axis is t
or time, the y-axis is y
or amplitude, and the z-axis is eigenfrequency number. The x and y data both have a dimension of t
, but the z-data has a dimension of 2D
. Is it possible to plot x,y,z data using z data with a different dimension than the x and y data in MATLAB using surf()
or plot3()
?
EDIT: This was a poorly formulated question. The idea was to plot x,y,z data using different dimensions, which is simply not possible.
Yes, you can use plot3
to plot it. To solve the length discrepancies, note that you just need to add one element to z
to make it the same length with t
and y
.
dt = 1;
M = 100; % [seconds]
D = 50; % number of masses
t = [0:dt:M];
y = randn(length(t),1); % [unitless] amplitude
z = [1:1:2*D+1]; % [unitless] number of eigenfrequencies
figure
plot3(t,y,z,'LineWidth', 2);
xlabel('t')
ylabel('y')
zlabel('z')
If you change the t
and y
dimension, you need to update the z
dimension accordingly. As I guess from you question, you want z
to be something from 1
up to 2*D
(two times the number of masses). Let's say you want to change the length of time here to 1000
, you can use linspace
to choose the correct step size for z
.
M = 1000; % [seconds]
D = 50; % number of masses
dt = 1;
t = [0:dt:M];
y = randn(length(t),1); % [unitless] amplitude
%z = [1:1:2*D]; % [unitless] number of eigenfrequencies
z = linspace(1,2*D,length(t));