User defined function in for loop

9 ビュー (過去 30 日間)
Doron Joffe
Doron Joffe 2021 年 12 月 1 日
編集済み: Doron Joffe 2021 年 12 月 1 日
I have created a loop to loop through a series of csv files and perform functions. The code I wrote is below:
file=('list of my files')
for i = 1:length(file)
csv = readtable(file{i});
Date=csv{1,2}
D(i,:)=Date %% I get a cell array with the dates from each file
end
The code that I wrote works but I need to transform it into a user-defined function. I have tried creating the function below. However, when I call the function I do not get the required results. Am I creating the function incorrectly?
function [csv,D] = read_function(i,file,a,b);
csv = readtable(file{i});
Date=csv{a,b};
D(i,:)=Date
end
%%% In a new window I call the function like this
file=('list of my files')
for i = 1:length(file)
a=1;
b=2;
[csv,D] = read_function(i,file,a,b);
end
  2 件のコメント
VBBV
VBBV 2021 年 12 月 1 日
Convert the csv variable to double and then pass it as function output argument. csv is table array and not double
Doron Joffe
Doron Joffe 2021 年 12 月 1 日
編集済み: Doron Joffe 2021 年 12 月 1 日
Thank you very much. Would I add a line to the function which states csv=table2array(csv) ?
It still seems to give problems when i try that.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB Compiler についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by