How can I make a 3d
Show older comments
Hello everyone, I have had problems when making a 3d plot for different rectangular pulses, in the 'y' axis the amplitude should go in voltage, in the 'x' axis the time, finally in the z axis the samples. I have searched for information but have not been able to find a good source.
Answers (1)
9 Comments
Star Strider
on 25 Jun 2022
My code only plots data.
The ‘s’ variable is a matrix, and my code plots each row, since that is how I wrote it.
Your data has a ‘Time’ column vector and a ‘Voltaje’ column vector, so to plot it in 3D, the code would be something like this:
figure
plot3(Time, ones(size(Time)), Voltaje)
grid on
view(50,50)
Make appropriate changes to get the result you want.
If you have a ‘Voltaje’ matrix with each signal a column vector, my code would change to:
figure
hold on
for k = 1:size(s,1)
plot3(Time, ones(size(Time))*5*k, Voltaje(:,k))
end
hold off
grid on
view(50,50)
This would plot the columns individually, similar to what my code plots. Note that this version addresses the columns of the ‘Voltaje’ vector rather than the rows of my original code.
.
David
on 26 Jun 2022
Star Strider
on 26 Jun 2022
These are separated on the y-axis, and they are separated arbitrarily by 5 units. That is the purpose of the ones call in the plot loop. (Separating them on the z-axis would separate them vertically, however that is not what the original plot in your question demonstrated.) The position of the ones call in the plot3 call argument list controls the axis on whcih they are separated, so experiment to get the result you want.
Star Strider
on 26 Jun 2022
You will need to do something like this —
Timem = cat(2,Time12, Time2,Time3,Time4); % Concatenate To Matrix
Voltajem = cat(2, Voltaje1,Voltaje2,Voltaje3,Voltaje4); % Concatenate To Matrix
figure
hold on
for k = 1:size(s,1)
plot3(Timem(:,k), ones(size(Timem,1))*k, Voltajem(:,k))
end
hold off
grid on
xlabel('Time (ns)')
ylabel('Sample')
zlabel('Ampliitude (a.u.)')
view(50,50)
That should get you started.
See the documentation on plot3 for details.
.
David
on 26 Jun 2022
Star Strider
on 26 Jun 2022
I created the ‘s’ matrix to illustrate the approach, since I do not have your data.
Use the code I previously posted instead:
Timem = cat(2,Time1,Time2,Time3,Time4); % Concatenate To Matrix
Voltajem = cat(2, Voltaje1,Voltaje2,Voltaje3,Voltaje4); % Concatenate To Matrix
figure
hold on
for k = 1:size(s,1)
plot3(Timem(:,k), ones(size(Timem,1))*k, Voltajem(:,k))
end
hold off
grid on
xlabel('Time (ns)')
ylabel('Sample')
zlabel('Ampliitude (a.u.)')
view(50,50)
Before you run it, be sure that all the appropriate ‘Time’ and ‘Voltaje’ vectors are in your workspace, and defined above (before) my code in your script.
.
Star Strider
on 26 Jun 2022
I have no idea what you are doing.
I got the impression that you have 4 (100000x1) vectors each for the independent and dependent variables. My code concatenates them into 2 (100000x4) matrices. That should be well within the ability of your computer to do.
Instead, you appear to be multiplying one of the vectors by its transpose.
David
on 26 Jun 2022
Star Strider
on 26 Jun 2022
That demonstration code is not appropriate for your data.
Use this instead:
Timem = cat(2,Time1,Time2,Time3,Time4); % Concatenate To Matrix
Voltajem = cat(2, Voltaje1,Voltaje2,Voltaje3,Voltaje4); % Concatenate To Matrix
figure
hold on
for k = 1:size(s,1)
plot3(Timem(:,k), ones(size(Timem,1))*k, Voltajem(:,k))
end
hold off
grid on
xlabel('Time (ns)')
ylabel('Sample')
zlabel('Ampliitude (a.u.)')
view(50,50)
.
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!