Read variable in .mat workspace

조회 수: 3 (최근 30일)
Racheal Butt
Racheal Butt 2022년 3월 23일
답변: Peter Perkins 2022년 3월 24일
Hi, I used the MATLAB mobile app to log sensor data (gyroscope, acceleration, etc), and it is saved as a .mat file. When I load it on MATLAB, it loads a workspace of variables.
The variables of the workspace of the .mat file is as follows:
I can access the acceleration timetable values with the code below:
matfile = "MobileSensorData/log3.mat"; %filename of the created .mat file from MATLAB Mobile
ld = load(matfile);
accel = [ld.Acceleration.X ld.Acceleration.Y ld.Acceleration.Z];
A snippet of the Acceleration timetable is as follows:
The issue I'm having is that I cannot access the variable t as I want to plot acceleration values against time
I tried
disp(ld.t)
to display the t values but comes with the error: Unrecognized field name "t".
Here's a snippet of the t variable:
Any help is greatly appreciated! I'm not too familiar with MATLAB, but am using it for my final year report.
Thank you in advance!
  댓글 수: 2
Walter Roberson
Walter Roberson 2022년 3월 23일
disp(ld.Acceleration.t)
Stephen23
Stephen23 2022년 3월 24일
@Racheal Butt: please upload a sample .mat file by clicking the paperclip button.
Note that you should NOT use the variable name MATFILE, as this is the name of a useful unbuilt function.

댓글을 달려면 로그인하십시오.

답변 (1개)

Peter Perkins
Peter Perkins 2022년 3월 24일
Rachael, the times are not part of the data, they are "metadata". But as your screenshot shows, the row times of the Acceleration timetable are named Timestamp. So, plot(Acceleration.Timestamp,Acceleration.X) or whatever.
Your screenshots contradict your code snippet, though. ld = load(matfile); puts everything under the additional layer of a scalar struct.
I have no idea what t is.

카테고리

Help CenterFile Exchange에서 Workspace Variables and MAT-Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by