필터 지우기
필터 지우기

Extract certain values in .mat file

조회 수: 1 (최근 30일)
Sleiman Ghorayeb
Sleiman Ghorayeb 2024년 4월 24일
편집: VBBV 2024년 4월 24일
Hi,
I have a mat file with 1250x1 data and I want to extract specific values from the 1250. For example I want to extract every 2nd or every 5th values.
As an example, the mat file contains the following values:
-0.13793 -0.114746 -0.204773 -0.224304 -0.181274 -0.192566 -0.159912 -0.174866 -0.134888 -0.148926
For every 2nd I want to read: -0.114746 -0.224304 -0.192566 -0.174866 -0.148926
For every 5th I want to read: -0.181274 -0.148926
What is the best command to do this? Thank you.
  댓글 수: 1
VBBV
VBBV 2024년 4월 24일
@Sleiman Ghorayeb To extract you need to first load the mat file into workspace and access the data variable

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

답변 (1개)

VBBV
VBBV 2024년 4월 24일
data= [-0.13793 -0.114746 -0.204773 -0.224304 -0.181274 -0.192566 -0.159912 -0.174866 -0.134888 -0.148926]
data = 1x10
-0.1379 -0.1147 -0.2048 -0.2243 -0.1813 -0.1926 -0.1599 -0.1749 -0.1349 -0.1489
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
data(2:2:end)
ans = 1x5
-0.1147 -0.2243 -0.1926 -0.1749 -0.1489
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
data(5:5:end)
ans = 1x2
-0.1813 -0.1489
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
  댓글 수: 2
Sleiman Ghorayeb
Sleiman Ghorayeb 2024년 4월 24일
Thank you for your response. Very helpful.
However, I read the original data file by using the "load" command.
Can I do this:
data=[hb]; %hb is the array containing all 1250 data points
data(2:2:end);
or
data(5:5:end);
VBBV
VBBV 2024년 4월 24일
편집: VBBV 2024년 4월 24일
@Sleiman Ghorayeb yes, you can if the datatype of hb is not a structure. It its a structure, then you need to use . (dot) operator to access data from structure. can you attach data file ?

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

카테고리

Help CenterFile Exchange에서 Graphics Object Identification에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by