-2
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)];

I want to apply the same function on all the 365 datasets I am having, but function can't work with any loop. Help me out with this

Pooja
  • 1

2 Answers2

0

Use function arrayfun, as explained in Matlab's documentation:

[B1,...,Bn] = arrayfun(Input,A1,...,An)

where Input is the name of your function and n equals 365, the number of datasets you have.

Dhia
  • 10,119
  • 11
  • 58
  • 69
0

I cant seem to find where you get variables SWI and P from, so make sure these are accessible to the function somehow.

Below is a brute force way of reading all (365?) files in a specific folder and feeding them through your algorithm one by one.

Hope this helps!

% Location of files to be read
folder = 'C:\foo\siffer\second 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