How to point to actual file for LISTDLG selection?

조회 수: 4 (최근 30일)
amh
amh 2023년 2월 23일
댓글: Rik 2023년 2월 23일
Hi,
I have a list of .mat files and only one to be selected at one time. I used listdlg to select the file each time.
fd = dir('*.mat');
fn = {fd.name};
[indx,tf] = listdlg('PromptString',{'Select a file.',...
'Only one file can be selected at a time.',''},...
'SelectionMode','single','ListString',fn);
The above code only up to selection point.
However, when i select the required file, and using this code;
xsel = fn(indx);
xsel returned at 1x1 cell instead the actual file in .mat.
How to point the xsel to actual .mat file in directory ?
.mat file consists acceleration data (120000x1) double

채택된 답변

Rik
Rik 2023년 2월 23일
You selected a file name. Now you need to use the load function to read the variables.
S=load(fn{indx});
  댓글 수: 3
amh
amh 2023년 2월 23일
Thanks for reply.
Rik
Rik 2023년 2월 23일
You're welcome, but you don't actually need struct2array, you can simply index the field of the struct.
So if the variable in the mat file is called acceleration, you can use xsel = x.acceleration;

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by