I want to access the vector data from several variables in a for loop. I have managed to build the string to load the filename and variables, but the actual data is not accessed.
this is the code:
vars={var1,var2,var3,var4};
for ii=1:length(vars)
file=dir(fullfile(maindirectory,'mydata.mat'));
filename=file.name
fullfilename=strcat(maindirectory,'\',filename);%builds the string
Data=load(fullfilename,vars{ii});
end
it all falls apart at Data.
The code just loads the struct with fields (var1: [99x1 double]), but not the actual data.

댓글 수: 1

Stephen23
Stephen23 2018년 9월 27일
편집: Stephen23 2018년 9월 27일
This is very confusing: it is not clear why you call dir when you already know the exact filename:
file=dir(fullfile(maindirectory,'mydata.mat'));
filename=file.name
fullfilename=strcat(maindirectory,'\',filename);%builds the string
Perhaps you just meant to do this:
fullfilename = fullfile(maindirectory,'mydata.mat');

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

답변 (1개)

Walter Roberson
Walter Roberson 2018년 9월 27일

0 개 추천

This is expected. Read the documentation on the output of load() applied to a mat file.

카테고리

도움말 센터File Exchange에서 MATLAB Mobile에 대해 자세히 알아보기

질문:

2018년 9월 27일

편집:

2018년 9월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by