How can I make a function from this few lines of codes?

1 Ansicht (letzte 30 Tage)
Ashfaq Ahmed
Ashfaq Ahmed am 17 Feb. 2023
Beantwortet: Voss am 17 Feb. 2023
Hi all, can anyone please tell me how can I make function of this calculation so that I can perform the same operation for any given range of A?
clear all; close all; clc;
A = -40:2:40;
B = A(find(A>0))./max(A);
C = -A(find(A<=0))./min(A);
D = [C,B];
figure(1),
subplot(2,1,1)
plot(1:numel(A),A);
subplot(2,1,2)
plot(1:numel(D),D)

Antworten (1)

Voss
Voss am 17 Feb. 2023
% calling the function defined below
filter_and_plot(-40:2:40)
% defining the function
function filter_and_plot(A)
B = A(find(A>0))./max(A);
C = -A(find(A<=0))./min(A);
D = [C,B];
figure()%(1),
subplot(2,1,1)
plot(1:numel(A),A);
subplot(2,1,2)
plot(1:numel(D),D)
end

Community Treasure Hunt

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

Start Hunting!

Translated by