Loading a file into a variable in funtion

I want to load a file in a variable in a function but when I do thta , matlab gives the file 's data in his own variable "ans"
function data=read_data(i)
data=load(num2str(i));
end

댓글 수: 1

Stephen23
Stephen23 2023년 1월 11일
편집: Stephen23 2023년 1월 12일
"matlab gives the file 's data in his own variable "ans""
How to call functions with output arguments is explained in the introductory tutorials:

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

답변 (1개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023년 1월 11일

0 개 추천

How you can call a function to load a data file, e.g.:
FName = 'MY_data'; % .txt data files that all contain the sequential name: MY_data1.txt, MY_data2.txt, etc.
N = input('Enter the number of data files to load: ');
for ii = 1:N
Name = stcat([FName, num2str(ii) '.txt']);
data{ii} = read_data(Name);
end
function data=read_data(Name)
data=load(Name);
end

카테고리

도움말 센터File Exchange에서 Workspace Variables and MAT Files에 대해 자세히 알아보기

제품

릴리스

R2021b

질문:

2023년 1월 11일

편집:

2023년 1월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by