Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Is it possible to call and run a different script for switched cases without changing the called function?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I have two scripts: one preparing/analysing data and the other plotting it. The analysis part filters signals; I would like to run this twice with the use of different filters and settings separately to see the change in the resulting plots. I know I can run the second script twice using a for-loop and inserting an IF/switch statement in the analsying part, but I wondered if something like this can be done from the 'calling' script, so i dont have to temper the other.
This is a snip of the analysis part (1):
switch runFilt
case 1
fcut = 400; % [Hz]
[B,A] = butter(1, fcut / (fsample/2),'low');
case 2
fcut = 10; % [Hz]
[B, A] = cheby1(5,0.9,fcut/(fsample/2),'low');
otherwise
return
end
matrix(5,:) = filtfilt(B, A, matrix(5,:));
matrix(6,:) = filtfilt(B, A, matrix(6,:));
processing{end+1} = ['Low-pass ', num2str(fcut), ' Hz'];
Snip of the calling function part (2):
for runFilt = 1:2 % number of scenarios
% Calling other scripts
step1_prepdata
step2_analyze_data
line06_m1 = nan(1,4);
line10_m1 = nan(1,4);
line14_m1 = nan(1,4);
line06_m2 = nan(1,4);
line10_m2 = nan(1,4);
line14_m2 = nan(1,4);
for ii = 1:4
switch runFilt
case 1
% M1
line06_m1(1,ii) = mean(m1(1).area(:,ii,2));
line10_m1(1,ii) = mean(m1(1).area(:,ii,3));
line14_m1(1,ii) = mean(m1(1).area(:,ii,4));
ButterM1 = [line06_m1; line10_m1; line14_m1];
case 2
line06_m1(1,ii) = mean(m1(1).area(:,ii,2));
line10_m1(1,ii) = mean(m1(1).area(:,ii,3));
line14_m1(1,ii) = mean(m1(1).area(:,ii,4));
ChebyM1 = [line06_m1; line10_m1; line14_m1]; % store to compare
otherwise
return
end
end
If anyone knows how to process part(1) into part(2) that would be very helpful. The reason is, I need to do several of these scenario-changes and I don't want to change a lot in such a large code. Thanks in advance.
0 Kommentare
Antworten (1)
Shashwat Bajpai
am 24 Jul. 2019
The customer wants to call another script from the present script without changing the content of the script being called.
Answer:
Hi,
I understand that you are trying to call your analyzing script in the calling script to and plot the results with different filters and values.
I suggest you write the analyzing script as a function and call it with different arguments so that you don’t have to change the contents of the script and it can be called as many times as desired. An example of the function can be as follows:
function [matrix,processing]=Filter(switch_case)
%Your code here
end
For more help on creating and using functions please refer the following link:
0 Kommentare
Diese Frage ist geschlossen.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!