calling a variable in another function
조회 수: 23 (최근 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
댓글 수: 0
채택된 답변
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
댓글 수: 0
추가 답변 (1개)
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!