calling a variable in another function
30 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
WILLBES BANDA
le 30 Mai 2020
Réponse apportée : Image Analyst
le 30 Mai 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
0 commentaires
Réponse acceptée
Image Analyst
le 30 Mai 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
0 commentaires
Plus de réponses (1)
Stephan
le 30 Mai 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
0 commentaires
Voir également
Catégories
En savoir plus sur Spreadsheets dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!