フィルターのクリア

Plot X, Y, Z axes with respect to time

43 ビュー (過去 30 日間)
Navin Johnson
Navin Johnson 2022 年 3 月 20 日
コメント済み: Voss 2022 年 3 月 21 日
So I have a file which contains the accelerometer values of a phone. The CSV file contains time, x, y and z columns. I am trying to find a way to plot the 3 axes (x, y and z) vs. time into one graph rather than using 'stackedplot'. How would one go about this?

採用された回答

Voss
Voss 2022 年 3 月 20 日
% making up some data:
t = 0:0.01:10;
x = cos(t);
y = sin(t);
z = t;
% plot x,y,z vs t in one plot:
figure();
plot(t,x,t,y,t,z);
legend('x','y','z');
xlabel('t');
grid on
% or make a 3d line whose points are (x,y,z):
figure();
plot3(x,y,z);
xlabel('x');
ylabel('y');
zlabel('z');
box on
grid on
  8 件のコメント
Navin Johnson
Navin Johnson 2022 年 3 月 21 日
Hi! Thank you so much for your time and answers! It works!
Voss
Voss 2022 年 3 月 21 日
Excellent! You're welcome!

サインインしてコメントする。

その他の回答 (1 件)

VBBV
VBBV 2022 年 3 月 20 日
編集済み: VBBV 2022 年 3 月 20 日
x_back_accel = cell2mat(backside_accel(:,1));
y_back_accel = cell2mat(backside_accel(:,2));
z_back_accel = cell2mat(backside_accel(:,3));
plot(t,x_back_accel,t,y_back_accel,t,z_back_accel);
Convert them to double array and plot it.
  5 件のコメント
VBBV
VBBV 2022 年 3 月 21 日
編集済み: VBBV 2022 年 3 月 21 日
You can use readmatrix function instead of readtable when importing data and to plot them using your initial code without having to use cell2mat
backside_accel = readmatrix('Lab5-Phone-BackSide/accelerometer.csv');
t = 0:0.1:4;
x_back_accel = backside_accel(:,1);
y_back_accel = backside_accel(:,2);
z_back_accel = backside_accel(:,3);
figure()
plot(t,x_back_accel,t,y_back_accel,t,z_back_accel);
Navin Johnson
Navin Johnson 2022 年 3 月 21 日
Oooh I'll try that

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by