function output=Input(data,T)
[x,cmap]=imread('abc.tiff');
data=im2double(x);
ID_notNaN=find(~isnan(SWI));
D=data(:,1);
X=data(:,2);
F=nan(length(data(:,1)),1);
P(ID_notNaN)=SWI;
output=[data(:,1),data(:,2)];
我想在我拥有的所有 365 个数据集上应用相同的函数,但函数不能与任何循环一起使用。帮我解决这个问题
我似乎找不到从哪里获取变量 SWI 和 P,因此请确保函数以某种方式可以访问这些变量。
下面是一种蛮力方法,用于读取特定文件夹中的所有(365?(文件,并通过您的算法逐个馈送它们。
希望这有帮助!
% Location of files to be read
folder = 'C:foosiffersecond try';
% Type of files to read. Leave as '' if you wish any ending.
ending = 'tiff';
% Find all files in that folder
files = dir(folder);
numFiles = length(a);
el = length(ending);
% Loop through all found files
for i = 1:numFiles
filename = files(i).name;
nameLength = length(filename);
% Ignore files with improper filename
if nameLength<el+1
% Not enough letters for containing .tiff
continue
elseif strcmp(filename(nameLength + (-el+1:0)) , ending)
% The file indeed has the right format
% Either just call your function here
% % output=Input(data,T);
% or paste the content of the
% function like i did :
[x,cmap]=imread([folder,filename]);
data=im2double(x);
ID_notNaN=find(~isnan(SWI));
D=data(:,1);
X=data(:,2);
F=nan(length(data(:,1)),1);
P(ID_notNaN)=SWI;
output=[data(:,1),data(:,2)];
end
end
使用函数arrayfun
,如 Matlab 的文档中所述:
[B1,...,Bn] = arrayfun(Input,A1,...,An)
其中Input
是函数的名称,n
等于 365,即您拥有的数据集数。