'strcmp' function not working when called through another function, but works when used directly
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
RANJITH REDDY KALLURI
le 9 Août 2017
Réponse apportée : KSSV
le 10 Août 2017
function Raw = pre_post(Data,ID,Sec)
lookup = {'Au Data Log ID','Measured CO','Measured Co2','Measured HC', 'Measured CH4', 'Measured NOx', 'Measured NO'};
Header = Data.Header(1,1:sum(~cellfun('isempty',Data.Header)));
lookup_location = zeros(1,length(lookup));
for i=1:length(lookup)
lookup_location(1,i) = find(strcmp(Header,lookup{i}),1);
end
Rawdata = Data.Data(:,lookup_location);
zero = find(Rawdata(:,1)==ID(1));
Span = find(Rawdata(:,1)==ID(2));
Back = find(Rawdata(:,1)==ID(3));
Raw = mean(Rawdata(zero(1)+Sec(1):zero(1)+Sec(2),2));
end
I have the above code as a function, when i call the function as
Raw = pre_post(Data,ID,Sec);
I see an error
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/166640/image.png)
But code works if run without the function. Can someone tell me what is wrong with the function.
0 commentaires
Réponse acceptée
KSSV
le 10 Août 2017
Try this:
function Raw = pre_post(Data,ID,Sec)
lookup = {'Au Data Log ID','Measured CO','Measured Co2','Measured HC', 'Measured CH4', 'Measured NOx', 'Measured NO'};
Header = Data.Header(1,1:sum(~cellfun('isempty',Data.Header)));
lookup_location = cell(length(lookup),1);
for i=1:length(lookup)
lookup_location{i} = find(strcmp(Header,lookup{i}),1);
end
Initialize lookup_location as a cell..cell can take non equal arrays. When you initialize lookup_location as a zeros matrix with 1 row..it expects only one element inside the loop using Strcmp..so the error popped out.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!