필터 지우기
필터 지우기

Loading .mat file problem

조회 수: 5 (최근 30일)
Sazcl
Sazcl 2023년 4월 18일
댓글: Sazcl 2023년 4월 18일
Hi everyone,
When I uploaded a .mat file to MATLAB, the name of the file appears as "ans" in workspace. Is there any way to correct it? Thanks in advance.

채택된 답변

VBBV
VBBV 2023년 4월 18일
편집: VBBV 2023년 4월 18일
Assign the data to a variable e.g. Data or Data1, Data2 ... if there are more than one file, and access the data using a dot operator as below,
% Assign the data in mat file to a variable
Data1 = load('data_B6_RC1.mat');
Data2 = load('data_B6_RC2.mat');
%...
% access the data from the Data variable ... Data is Struct variable
t = Data1.data_B6_RC1(1,:);
vs = Data1.data_B6_RC1(2,:);
vc = Data1.data_B6_RC1(3,:);
  댓글 수: 1
Sazcl
Sazcl 2023년 4월 18일
it worked, thanks!

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

추가 답변 (1개)

Cameron
Cameron 2023년 4월 18일
It looks like when the .mat file was saved, the variables weren't saved with their proper names. You could just keep it as it is and do this:
load('data_B6_RC.mat');
t = ans(1,:);
vs = ans(2,:);
vc = ans(3,:);
Or you could resave it as
load('data_B6_RC.mat');
t = ans(1,:);
vs = ans(2,:);
vc = ans(3,:);
save('data_B6_RC_new.mat','t','vs','vc')
and just use the data_B6_RC_new.mat file instead. Or you could overwrite the old file.
  댓글 수: 1
Sazcl
Sazcl 2023년 4월 18일
I know that the first block of code works, but there is a problem with it: when I upload more than one file, only the last uploaded file appears in workspace because both of them are in workspace with the name "ans". Unfortunately, the second code block didn't work for me.

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

카테고리

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