calling a variable in another function

27 visualizaciones (últimos 30 días)
WILLBES BANDA
WILLBES BANDA el 30 de Mayo de 2020
Respondida: Image Analyst el 30 de Mayo de 2020
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

Respuesta aceptada

Image Analyst
Image Analyst el 30 de Mayo de 2020
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

Más respuestas (1)

Stephan
Stephan el 30 de Mayo de 2020
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

Categorías

Más información sobre Import, Export, and Conversion en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by