Filter löschen
Filter löschen

Loading a file into a variable in funtion

1 Ansicht (letzte 30 Tage)
Leonidas
Leonidas am 11 Jan. 2023
Bearbeitet: Stephen23 am 12 Jan. 2023
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 Kommentar
Stephen23
Stephen23 am 11 Jan. 2023
Bearbeitet: Stephen23 am 12 Jan. 2023
"matlab gives the file 's data in his own variable "ans""
How to call functions with output arguments is explained in the introductory tutorials:

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov am 11 Jan. 2023
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

Kategorien

Mehr zu Large Files and Big Data finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by