calling a variable in another function

31 ビュー (過去 30 日間)
WILLBES BANDA
WILLBES BANDA 2020 年 5 月 30 日
回答済み: Image Analyst 2020 年 5 月 30 日
Hi, i have 2 functions where i calculated a variable in function 1, now i want to use the variable in function 2 but it says variable not recognised. In my case i calculated TableFiles(which has names of excel spreadsheets) in function 1 and i want to open the files in function 2 using read cell. Please help
function [LookupTableFiles]=getaerotablelisting( FilePrefix, DirectoryName , filetype )
FileList = dir('DynamicData*.xlsx')
TableFiles = {};
for LenFlLst = 1:numel(FileList)
TableFiles = {FileList.name}
end
end
function [Cols,StructOut]=getindepvars( CurrentSheet )
for LenTables = 1:size(CurrentSheet)
CurrentSheet = readcell(TableFiles);
Raw = CurrentSheet;
if ischar(Raw{1,1}) == 1
IndepVariablename = Raw(1,1);
Range = Raw(2:end,1);
StructOut.(Raw{1,1}) = [Range{:}];
a = size(Raw);
Cols = a(:,2);
end
end
end

採用された回答

Image Analyst
Image Analyst 2020 年 5 月 30 日
Pass it in when you call the second function:
function LookupTableFiles = getaerotablelisting( FilePrefix, DirectoryName , filetype )
FileList = dir('DynamicData*.xlsx')
LookupTableFiles = {FileList.name}
end
function [Cols,StructOut]=getindepvars( CurrentSheet, LookupTableFiles )
for LenTables = 1:size(CurrentSheet)
CurrentSheet = LookupTableFiles{LenTables};
Raw = CurrentSheet;
if ischar(Raw{1,1}) == 1
IndepVariablename = Raw(1,1);
Range = Raw(2:end,1);
StructOut.(Raw{1,1}) = [Range{:}];
a = size(Raw);
Cols = a(:,2);
end
end
end
Lots of other problems with that code but I don't have time now to fix them all....sorry

その他の回答 (1 件)

Stephan
Stephan 2020 年 5 月 30 日
function [LookupTableFiles]=getaerotablelisting( FilePrefix, DirectoryName , filetype )
FileList = dir('DynamicData*.xlsx')
TableFiles = {};
for LenFlLst = 1:numel(FileList)
TableFiles = {FileList.name}
end
function [Cols,StructOut]=getindepvars( CurrentSheet )
for LenTables = 1:size(CurrentSheet)
CurrentSheet = readcell(TableFiles);
Raw = CurrentSheet;
if ischar(Raw{1,1}) == 1
IndepVariablename = Raw(1,1);
Range = Raw(2:end,1);
StructOut.(Raw{1,1}) = [Range{:}];
a = size(Raw);
Cols = a(:,2);
end
end
end
end

カテゴリ

Help Center および File ExchangeImport, Export, and Conversion についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by